Hello!
I have worked on 1/2 day on trying to get this work. It is bombing at the ExecuteNonQuery() call. I would greatly apprecaite it if you all could looke at this simple SQL code and give any suggestions that you might have.
That's the weirdest code I've seen. Did you just copy the code from elsewhere?
You have
cnn = new SqlConnection(connetionString);
cnn.Open();
cmd = new SqlCommand(sql, cnn);
... OK so far but what's in the "sql"? It's supposed to be a query string.
Then down here, you create a new SqlCommand WITHOUT specifying the databse connection and try to execute it?? So this SQLCmd has all the data. It just doesn't have any info on a database it's supposed to connect to.
MikeKiser
Member
17 Points
49 Posts
SQLCmd/ExecuteNonQuery not working...please help!
Jan 31, 2013 08:19 PM|LINK
Hello!
I have worked on 1/2 day on trying to get this work. It is bombing at the ExecuteNonQuery() call. I would greatly apprecaite it if you all could looke at this simple SQL code and give any suggestions that you might have.
Thanks! Mike
cnn = new SqlConnection(connetionString);
cnn.Open();
cmd = new SqlCommand(sql, cnn);
string sPath = "test"; string sDescription = "test"; string sMainOrExtra = "test"; string sCaseID = "test";
string insertString = @"insert into CodeParms(FileAndPathName, CASEID, MainOrExtr, [Desc])" + " VALUES (@sPath, @sDescription, @sMainOrExtra, @sCaseID)";
using (var SQLCmd = new SqlCommand(insertString)) {
SQLCmd.Parameters.Add("@sPath", SqlDbType.Char).Value = sPath; SQLCmd.Parameters.Add("@sCaseID", SqlDbType.Char).Value = sCaseID; SQLCmd.Parameters.Add("@sMainOrExtra", SqlDbType.Char).Value = sMainOrExtra; SQLCmd.Parameters.Add("@sDescription",SqlDbType.Char).Value = sDescription;
SQLCmd.ExecuteNonQuery();
cnn.Close();
teddy_q
Member
712 Points
139 Posts
Re: SQLCmd/ExecuteNonQuery not working...please help!
Feb 01, 2013 01:34 AM|LINK
That's the weirdest code I've seen. Did you just copy the code from elsewhere?
You have
cnn = new SqlConnection(connetionString);
cnn.Open();
cmd = new SqlCommand(sql, cnn);
... OK so far but what's in the "sql"? It's supposed to be a query string.
Then down here, you create a new SqlCommand WITHOUT specifying the databse connection and try to execute it?? So this SQLCmd has all the data. It just doesn't have any info on a database it's supposed to connect to.
using (var SQLCmd = new SqlCommand(insertString))