使用vb.net开发数据库软件但该程序无法保存到数据库。
If Microsoft.VisualBasic.Right(Application.StartupPath, 1) = "\" Then
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\database2.accdb"
Else
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\database2.accdb"
End If
conn = New OleDbConnection(sConnString)
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO PersonalData (Title, Full Name,Department,Unit,Phone No,Email,Gender,Marital Status,Birthday,Spouse Birthday,Wedding Anniversary,Educational Qualification,No of Kids,Work Experience) VALUES (@Title, @Full Name,@Department,@unit,@Phone No,@Email,@Gender,@Marital Status,@Birthday,@Spouse Birthday,@Wedding Anniversary,@Educational Qualification,@No of Kids,@Work Experience)"
cmd.Parameters.Add("@Title", OleDbType.VarChar).Value = TextBox1.Text
cmd.Parameters.Add("@Full Name", OleDbType.VarChar).Value = TextBox2.Text
cmd.Parameters.Add("@Department", OleDbType.VarChar).Value = TextBox3.Text
cmd.Parameters.Add("@unit", OleDbType.VarChar).Value = TextBox4.Text
cmd.Parameters.Add("@Phone No", OleDbType.VarChar).Value = TextBox5.Text
cmd.Parameters.Add("@Email", OleDbType.VarChar).Value = TextBox6.Text
cmd.Parameters.Add("@Gender", OleDbType.VarChar).Value = TextBox7.Text
cmd.Parameters.Add("@Marital Status", OleDbType.VarChar).Value = TextBox8.Text
cmd.Parameters.Add("@Birthday", OleDbType.VarChar).Value = TextBox9.Text
cmd.Parameters.Add("@Spouse Birthday", OleDbType.VarChar).Value = TextBox10.Text
cmd.Parameters.Add("@Wedding Anniversary", OleDbType.VarChar).Value = TextBox11.Text
cmd.Parameters.Add("@Educational Qualification", OleDbType.VarChar).Value = TextBox12.Text
cmd.Parameters.Add("@No of Kids", OleDbType.VarChar).Value = TextBox13.Text
cmd.Parameters.Add("@Work Experience", OleDbType.VarChar).Value = TextBox14.Text
cmd.ExecuteNonQuery()
MsgBox("Data Uploaded Successfully.", , " ")
它显示语法错误指向cmd.ExecuteNonQuery
,但相同的代码适用于另一个软件。
答案 0 :(得分:0)
您必须提供错误以了解在执行查询期间发生的情况,但是如果没有在连接上给出任何错误,请查看您的代码MAYBE错误在变量内。
我做了一个例子,如果你有一个字符串,其中有一个特殊的字符,如'您需要将其替换为''
示例:
mystring = mystring.Replace("'","''")
如果可以帮助您,请点击它,如果没有错误消息,可以提供帮助。