Click here to Skip to main content
15,887,349 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlConnection con = new SqlConnection(@"data source=.\SQLEXPRESS;database= Registration; trusted_connection=yes ");
        SqlDataAdapter sd = new SqlDataAdapter();
        public Form1()
        {
            InitializeComponent();
        }

        private void btnADD_Click(object sender, EventArgs e)
        {
            
            sd.InsertCommand = new SqlCommand("insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)", con);
            sd.InsertCommand.Parameters.Add("@firstname", SqlDbType.VarChar).Value = tbfname.Text;
            sd.InsertCommand.Parameters.Add("@lastname", SqlDbType.VarChar).Value = tblname.Text;
           sd.InsertCommand.Parameters.Add("@mobile", SqlDbType.Int).Value =Convert.ToInt32(tbmobile.Text);
            sd.InsertCommand.Parameters.Add("@emailid", SqlDbType.VarChar).Value = tbemail.Text;
            con.Open();
            sd.InsertCommand.ExecuteNonQuery();
            con.Close();
        }
    }



It showing "Incorrect syntax near 'VALUE'." at "sd.InsertCommand.ExecuteNonQuery();"
Posted
Updated 25-May-12 0:20am
v2
Comments
Uday P.Singh 25-May-12 6:21am    
Try : insert into DBtest values
selflearning 25-May-12 6:46am    
Thanks
hitech_s 25-May-12 6:24am    
replace this line "sd.InsertCommand = new SqlCommand("insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)", con);"

with


sd.InsertCommand = new SqlCommand("insert into DBtest VALUES(@firstname, @lastname, @mobile, @emailid)", con);
selflearning 25-May-12 6:46am    
thanks...

It's VALUES not VALUE:
C#
sd.InsertCommand = new SqlCommand("insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)", con);
Becomes
C#
sd.InsertCommand = new SqlCommand("insert into DBtest VALUES(@firstname, @lastname, @mobile, @emailid)", con);

However, it is a good idea to name the fields they are going to go into - that way a later database change does not screw your program up!
SQL
INSERT INTO Videos (Id, ImageFront, ImageBack, ImageCombined, Title) VALUES (@ID, @CF, @CR, @CB, @TI)
 
Share this answer
 
Comments
hitech_s 25-May-12 6:26am    
nice my 5!
Maciej Los 25-May-12 6:27am    
Good work, +5!
I was late :(
VJ Reddy 25-May-12 6:39am    
Good answer. 5!
selflearning 25-May-12 6:45am    
Thank you very much....
OriginalGriff 25-May-12 7:13am    
You're welcome!
Take a look at the differences between quesries:
SQL
insert into DBtest VALUE(@firstname, @lastname, @mobile, @emailid)

Correct one is:
SQL
insert into DBtest (Column1, Column2, Column3, Column4)
VALUES(@firstname, @lastname, @mobile, @emailid)
 
Share this answer
 
Comments
VJ Reddy 25-May-12 6:39am    
Good answer. 5!
Maciej Los 25-May-12 6:43am    
Thank you, VJ ;)
selflearning 25-May-12 6:46am    
Thank you...
Maciej Los 26-May-12 16:25pm    
You're welcome ;)
Shahin Khorshidnia 26-May-12 12:07pm    
+5 good solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900