Using Visual C# and SQL cannot insert data into table..

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello everyone,
I was hoping someone would be able to shine some light on my problem.
I am not getting any errors but when I check my data table none of the data has been inserted.
The datatable is attached to my project and my connection string is working I checked by putting " Messagebox.show(W7connection.State.ToString());" just before the ExecuteNonQuery line and it shows "OPEN".
Anyway heres the code Im having trouble with. Any help would be greatly appreaciated :)

<pre class="prettyprint ReasonDA.InsertCommand = new SqlCommand("INSERT INTO Reason(Reason,Reason2,TreatyCountry,TreatyNumber,ExceptionType,Other) VALUES (@Reason,@Reason2,@TreatyCountry,@TreatyNumber,@ExceptionType,@Other)", W7Connection);
ReasonDA.InsertCommand.Parameters.Add("@Reason", SqlDbType.NVarChar).Value = ReasonChoiceTxt.Text.Trim();
ReasonDA.InsertCommand.Parameters.Add("@Reason2", SqlDbType.NVarChar).Value = ReasonChoiceTxt2.Text.Trim();
ReasonDA.InsertCommand.Parameters.Add("@TreatyCountry", SqlDbType.Int).Value = Convert.ToInt32(TreatyCountryComboBox.SelectedValue);
ReasonDA.InsertCommand.Parameters.Add("@TreatyNumber", SqlDbType.NVarChar).Value = TreatyNoTxt.Text;
ReasonDA.InsertCommand.Parameters.Add("@ExceptionType", SqlDbType.NVarChar).Value = ExceptionComboBox.Text;
ReasonDA.InsertCommand.Parameters.Add("@Other", SqlDbType.NVarChar).Value = OtherInfoTxt.Text;
W7Connection.Open();
ReasonDA.InsertCommand.ExecuteNonQuery();
W7Connection.Close(); [/code]

View the full article
 
Back
Top