我一直在为此排查一个星期。我尝试将一个值插入到SQL Server数据库中。它不显示任何错误,但是当我检查数据库时,没有插入任何数据。我可能在这里做错了什么,但我找不到它。感谢您的帮助。ASP.NET,VB.NET无法将数据插入到SQL Server数据库中
Dim connect As New SqlConnection(ConfigurationManager.ConnectionStrings("SqlServer").ToString())
Using coa As New SqlCommand()
With coa
.Connection = connect
.CommandType = CommandType.Text
End With
Try
connect.Open()
Dim insertcmd As String
insertcmd = "insert into tblUserSection (@newValue, @SectionName, @newSectionID) values ," _
& "@newValue, @SectionName, @newSectionID);"
coa.Parameters.Add(New SqlParameter("@newValue", SqlDbType.BigInt))
coa.Parameters("@newValue").Value = newValue
coa.Parameters.Add(New SqlParameter("@SectionName", SqlDbType.NVarChar))
coa.Parameters("@SectionName").Value = SectionName.ToString
coa.Parameters.Add(New SqlParameter("@newSectionID", SqlDbType.BigInt))
coa.Parameters("@newSectionID").Value = newSectionID
coa.ExecuteNonQuery()
connect.Close()
MsgBox("success insert")
Catch ex As Exception
MsgBox("Fail to Save to database")
End Try
End Using
不知道为什么你不会看到一个异常;该查询字符串看起来不正确。 –
任何想法如何写一个正确的查询? –
我编辑来自Microsoft页面的示例以符合我的代码。 –