insert sql
-
Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5
-
Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5
-
Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5
May be the user via which u r connecting to db doesnt have permisions to insert or update in this table
-
do you get an error message? When you look in the quickwatch: what does the 'queryString' variable have as value? Coulda, woulda, shoulda doesn't matter if you don't.
I don't get an error message, that's the problem. I don't really understand what you mean with quickwatch, but if you mean what the output is at the end it gives: QUERY: bla bla inserted When I do this query directly with sql in the database it there is no problem. Regards William wistiti 5
-
May be the user via which u r connecting to db doesnt have permisions to insert or update in this table
-
Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5
. . . . SqlCommand command = new SqlCommand(); command.Connection = connection ; command.CommandText = queryString; try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } _____________________ Proud to be Albanian _____________________
-
I don't get an error message, that's the problem. I don't really understand what you mean with quickwatch, but if you mean what the output is at the end it gives: QUERY: bla bla inserted When I do this query directly with sql in the database it there is no problem. Regards William wistiti 5
No what I meant was: in debug mode (set a breakpoint) If the variable is assigned hover over the variable with your cursor, right-click and choose quick watch. You'll get a dialog with some info. The cool thing about quickwatch is that you can alter the data or see entire objects. Coulda, woulda, shoulda doesn't matter if you don't.