locked
Adding a row to SQL table RRS feed

  • Question

  • Hello all,

    I'm trying to add a new row to my SQL table.

    Here is my Code:

    private void AddBtn_Click(object sender, EventArgs e)
    
    
    
     {
    
    
    
      if (Validate() && (RaceBS != null))
    
    
    
      {
    
    
    
      RaceBS.AddNew();
    
    
    
      Refresh();
    
    
    
      }
    
    
    
     }

    I know that I need to write an sqlcommand somewhere so the data could be saved into the table.

    But I don't know where or how.

    One more thing I use some variables like: VarChar, Int, Float

    Need some advice.

    Thanks.


    lioritshiran@gmail.com
    • Edited by lioritshiran Saturday, October 2, 2010 4:57 PM adding
    Saturday, October 2, 2010 4:43 PM

Answers

  • The syntax for adding a row in SQL is:

    INSERT INTO Your_Table (parameter1, parameter2...) VALUES (value_for_parameter1, value_for_parameter2...)

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    • Proposed as answer by Noam B Sunday, October 3, 2010 10:55 AM
    • Marked as answer by Larcolais Gong Friday, October 8, 2010 3:54 AM
    Sunday, October 3, 2010 10:55 AM
  • Hi lioritshiran,

    Thank you for your post.

    Based on your description, please check the following code snippets.

    System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection("YOUR CONNECTION STRING");
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
    cmd.CommandType = System.Data.CommandType.Text;
    cmd.CommandText = "INSERT Region (RegionID, RegionDescription) VALUES (5, 'NorthWestern')";
    cmd.Connection = sqlConnection1;
    sqlConnection1.Open();
    cmd.ExecuteNonQuery();
    sqlConnection1.Close();

    If you have any issues or concerns, please feel free to let me know.
    CHEERS,
    Larcolais


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, October 4, 2010 7:50 AM

All replies

  • You need to provide more source code, we do not know what is RaceBS


    With kind regards
    Krystian Zieja
    http://www.projectnenvision.com
    Follow me on twitter
    My Blog
    Saturday, October 2, 2010 4:45 PM
  • RaceBS is BindingSource

    I also have a Connection String, Data Adapter and Data Set. All relate to my SQL database/table.

    I need a simple code sample that shows how to add a new row to an SQL table


    lioritshiran@gmail.com
    Saturday, October 2, 2010 4:59 PM
  • The syntax for adding a row in SQL is:

    INSERT INTO Your_Table (parameter1, parameter2...) VALUES (value_for_parameter1, value_for_parameter2...)

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    • Proposed as answer by Noam B Sunday, October 3, 2010 10:55 AM
    • Marked as answer by Larcolais Gong Friday, October 8, 2010 3:54 AM
    Sunday, October 3, 2010 10:55 AM
  • Hi lioritshiran,

    Thank you for your post.

    Based on your description, please check the following code snippets.

    System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection("YOUR CONNECTION STRING");
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
    cmd.CommandType = System.Data.CommandType.Text;
    cmd.CommandText = "INSERT Region (RegionID, RegionDescription) VALUES (5, 'NorthWestern')";
    cmd.Connection = sqlConnection1;
    sqlConnection1.Open();
    cmd.ExecuteNonQuery();
    sqlConnection1.Close();

    If you have any issues or concerns, please feel free to let me know.
    CHEERS,
    Larcolais


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, October 4, 2010 7:50 AM