Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   C# with SQL [Window Forms Help] (http://www.go4expert.com/forums/c-sharp-sql-window-forms-help-t19401/)

faizulhaque 13Sep2009 02:18

C# with SQL [Window Forms Help]
Hello Every C# PRogrammer and Others:

I need help in C# database programming. i need to save textbox text into table of c#
Here is code

// create command
        SqlConnection conn = new SqlConnection(@"server = .\sqlexpress;integrated security = true;database = office");
        string query = @"insert into emp('"+txtid.Text+"','"+txtname.Text+"','"+txtdesig.Text+"','"+txtsal.Text+"','"+txtjoin.Text+"','"+txtadd.Text+"','"+txtjoin.Text+"','"+txtcont.Text+"');";
        SqlCommand cmd = new SqlCommand(query, conn);

This code is In Save Button:

but when i execute this always Getting Error: as incorrrect Syntex.

Any Help suggestion

nimesh 13Sep2009 12:58

Re: C# with SQL [Window Forms Help]
yes, you will get an error of Incorrect Syntax, because the Insert statement is not correct.

The correct syntax would be:
1] If you want to insert all values

"insert into emp values('"+txtid.Text+"','"+txtname.Text+"','"+txtdesig.Text+"','"+txtsal.Text+"','"+txtjoin.Text+"','"+txtadd.Text+"','"+txtjoin.Text+"','"+txtcont.Text+"');";
2] If you want to insert specific values

"insert into emp(id,name,desig,sal) values('"+txtid.Text+"','"+txtname.Text+"','"+txtdesig.Text+"','"+txtsal.Text+"');";

faizulhaque 14Sep2009 03:12

Re: C# with SQL [Window Forms Help]
Issue Solved THanks Mate:

All times are GMT +5.5. The time now is 22:26.