【发布时间】:2015-08-21 03:51:27
【问题描述】:
我已经解决了一周的问题。我尝试在 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 页面编辑示例以适合我的代码。
-
您可能将数据插入到一个数据库中,然后在另一个数据库中查找。
-
我已经从其他表中获取数据。我发出警报以打印出该值,它确实显示了该值。问题是,数据库中没有更新。
标签: sql sql-server database vb.net