SQL and ASP.NET

Im just fiddleing around some, trying to make an SQL insert<BR>into a database with C# and ASP.NET (MSSQL 7.0)<BR><BR>It says i need to declare the variable @strSubject i know<BR>im defineing the variables wrong, but i can't find an<BR>example anywhere, so im posting here.<BR><BR>void SubmitBtn_Click(Object Src, EventArgs E) {<BR><BR> string @strSubject = "test1";<BR> string @strMessage = "test2";<BR> <BR> SQLConnection myConnection = new SQLConnection("server=localhost;uid=not4u;pwd=not4u;database=not4 u");<BR> SQLDataSetCommand myDataSetCommand = new SQLDataSetCommand("SELECT * FROM tbl_guestbook",myConnection);<BR> myDataSetCommand.InsertCommand.CommandText = "INSERT INTO tbl_guestbook (main_subject, main_message) VALUES (@strSubject,@strMessage)";<BR> myDataSetCommand.InsertCommand.ActiveConnection = (SQLConnection) myDataSetCommand.SelectCommand.ActiveConnection.Cl one();<BR> myDataSetCommand.InsertCommand.ActiveConnection.Op en();<BR> myDataSetCommand.InsertCommand.Execute();<BR>myDataSetCommand.InsertCommand.ActiveConnection.Cl ose();<BR> }<BR><BR>Thanks in advance.<BR><BR>/JoakimBuild your insert statement as follows:<BR>myDataSetCommand.InsertCommand.CommandText = "INSERT INTO tbl_guestbook (main_subject, main_message) VALUES (" + "'" +@strSubject + ", '" + @strMessage +"')"; <BR>Thanks alot!<BR>That line didn't work right away, but now i understand<BR>how to build the line so i got it to work, thanks again.<BR><BR>/JoakimMay be this is right<BR><BR>string strSubject="your subject";<BR>string strMessage="your message";<BR> <BR>myDataSetCommand.InsertCommand.CommandText = "INSERT INTO tbl_guestbook (main_subject, main_message) VALUES (" + "'" +strSubject + ", '" + strMessage +"')";
 
Back
Top