我查看了 StackOverflow 以及其他一些网站,我发现了一些代码可以将它们组合在一起:
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Dim sqlConnection As SqlConnection
Dim sqlCommand As SqlCommand
Dim sqlString, iName, iDescription As String
Dim iQuantity As Integer
Dim iPrice As Decimal
Protected Sub cmdAddStock_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles cmdAddStock.Click
iName = txtItemName.Text
iDescription = txtDescription.Text
iQuantity = txtQuantity.Text
iPrice = txtPrice.Text
Using myConnection As New SqlConnection("Server=localhost;Database=BBBLeeds;
Trusted_Connection=True")
myConnection.Open()
sqlCommand = New SqlCommand("INSERT INTO tblItem(ItemName, Description,
Price, Stock) values('" + iName + "','" + iDescription + "','" + iPrice +
"','" + iQuantity + "')")
sqlCommand.ExecuteNonQuery()
myConnection.Close()
Response.Redirect(Request.RawUrl, True)
End Using
End Sub
End Class
返回的错误如下:
“从字符串“INSERT INTO tblItem(ItemName, De”到类型“Double”的转换无效。”
这是使用 SQL 的数据结构:
http://i23.photobucket.com/albums/b368/Damo115/Untitled.png
感谢您提供的任何建议。