无法将数据插入Microsoft SQL Server [英] Unable insert data into Microsoft SQL Server

查看:83
本文介绍了无法将数据插入Microsoft SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用asp.net开发一个Web应用程序.但是我无法将数据插入数据库.可以提供任何示例代码吗?

Currently I''m develop a web application using asp.net. But I unable to insert data into database.Any sample code can be provided?

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.

推荐答案

如果您发布了确切的代码,请使用Dorababu743的解决方案
if you have posted exact code then go with the solution of Dorababu743


您错过了一些引号字符.替换一个:

You have missed some quote characters. Replace this one :

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


有了这个:


With this one :

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.


请提供示例以继续进行操作.

告诉我错误您得到了什么
Please provide sample to proceed further.

Tell me the error what you getting


这篇关于无法将数据插入Microsoft SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆