Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Currently I'm develop a web application using asp.net. But I unable to insert data into database.Any sample code can be provided?

VB
Dim constring As String = "Data Source = USER-PC\SQLEXPRESS; Initial catalog = PatientDiagnose; Persist Security Info= True; User ID = Thalassemia; Password = Ling123!@#"
Dim con As SqlConnection = New SqlConnection(constring)
Dim ds As New DataSet
Dim adapter As New SqlDataAdapter
 con.Open()
Dim insertCommand As String = "Insert into DoctorRecord (DocFirst,DocLast) values ('  " & TextBoxFirst.Text & ", " & TextBoxLast.Text & "')"
adapter.SelectCommand = New SqlCommand(insertCommand, con)
adapter.Fill(ds)


Error: There are more columns in the INSERT statement than the values specified in the VALUES clause.
Posted
Updated 20-Nov-11 22:49pm
v2
Comments
HL22 21-Nov-11 4:48am    
Dim constring As String = "Data Source = USER-PC\SQLEXPRESS; Initial catalog = PatientDiagnose; Persist Security Info= True; User ID = Thalassemia; Password = Ling123!@#"
Dim con As SqlConnection = New SqlConnection(constring)
Dim ds As New DataSet
Dim adapter As New SqlDataAdapter
con.Open()
Dim insertCommand As String = "Insert into DoctorRecord (DocFirst,DocLast) values (' " & TextBoxFirst.Text & ", " & TextBoxLast.Text & "')"
adapter.SelectCommand = New SqlCommand(insertCommand, con)
adapter.Fill(ds)


Error: There are more columns in the INSERT statement than the values specified in the VALUES clause.
demouser743 21-Nov-11 4:48am    
Post the code What you have tried so far.. Inserting the data to database is not a tough ask
demouser743 21-Nov-11 4:50am    
Means you are trying to insert extra item to the table which is not defined. Check out your columns in the table
HL22 21-Nov-11 4:52am    
For example, in my table I have 11 columns,when I only insert 1 data into 1 column.It can work.But if I insert 11 data into the table...then prompt this error message...
HL22 21-Nov-11 4:53am    
Is there any error with my code for inserting data into database?

if you have posted exact code then go with the solution of Dorababu743
 
Share this answer
 
Comments
demouser743 21-Nov-11 6:20am    
Why you post it as answer dude.. It seems to be a comment
You have missed some quote characters. Replace this one :

VB
Dim insertCommand As String = "Insert into DoctorRecord (DocFirst,DocLast) values ('  " & TextBoxFirst.Text & ", " & 

With this one :

VB
Dim insertCommand As String = "Insert into DoctorRecord (DocFirst,DocLast) values ('" & TextBoxFirst.Text & "', '" & 


The first code embraces two strings into one quoted string so you see that error.

Hope It Helps.
 
Share this answer
 
Comments
HL22 21-Nov-11 5:12am    
Thanks.It have been solved....
Amir Mahfoozi 21-Nov-11 5:18am    
Good Luck
Please provide sample to proceed further.

Tell me the error what you getting
 
Share this answer
 
Comments
demouser743 21-Nov-11 4:47am    
Post this as a comment. Do you think this an answer :-o
I don't know what's your error is but as i am not that much good with VB coding i will post the sample code for inserting values try this and let me know

C#
"INSERT INTO Customers(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11) VALUES(" & _
                        "'" & txtData1.Text & "'," & _
                        "'" & txtData2.Text & "'," & _
                        "'" & txtData3.Text & "'," & _
                        "'" & txtData4.Text & "'," & _
                        "'" & txtData5.Text & "'," & _
                        "'" & txtData6.Text & "'," & _
                        "'" & txtData7.Text & "'," & _
                        "'" & txtData8.Text & "'," & _
                        "'" & txtData9.Text & "'," & _
                        "'" & txtData10.Text & "'," & _
                        "'" & txtData11.Text & "')"


Paste your controls instead of mine and give it a try
 
Share this answer
 
v2
Comments
HL22 21-Nov-11 5:09am    
Now it able to work....Really THANKS a lotsssss......
demouser743 21-Nov-11 5:11am    
Welcome mark as answer if it resolves ur problem
HL22 21-Nov-11 5:12am    
OKOK...

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