输入字符串的格式不正确??
修改记录时怎么都是显示"必须为价格输入一个数字类型的值"?为价格输入了数字类型的值后还是的.注释掉判断价格是否为数字类型的函数后错误为"输入字符串的格式不正确。"?出错处为mycommand.ExecuteNonQuery()??
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
conn = New SqlConnection("server=wiz02;uid=tree;pwd=tree;database=bookforstudy")
If Not IsPostBack Then
grid_bind()
End If
End Sub
Function PriceIsNotNumberic(ByVal price) As Boolean
If IsNumeric(price) = False Then
Lblmessage.Text = "错误:必须为价格输入一个数字类型的值"
Lblmessage.ForeColor = Color.Red
grid_bind()
Return (True)
Else
Return (False)
End If
End Function
Private Sub mydatagrid_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles mydatagrid.UpdateCommand
Dim updatecmd As String = _
"update book set ID= @ID,author= @author,publisher= @publisher,price= @price,title= @title where ID= @ID"
Dim mycommand As SqlCommand = New SqlCommand(updatecmd, conn)
mycommand.Parameters.Add(New SqlParameter("@id", SqlDbType.Int, 10))
mycommand.Parameters.Add(New SqlParameter("@author", SqlDbType.VarChar, 50))
mycommand.Parameters.Add(New SqlParameter("@publisher", SqlDbType.VarChar, 50))
mycommand.Parameters.Add(New SqlParameter("@price", SqlDbType.Money, 10))
mycommand.Parameters.Add(New SqlParameter("@title", SqlDbType.VarChar, 50))
mycommand.Parameters("@ID").Value = mydatagrid.DataKeys(e.Item.ItemIndex)
Dim cols() As String = {"@author", "@publisher", "@price", "@title"}
Dim numcols As Integer = e.Item.Cells.Count
Dim i As Integer
For i = 1 To numcols - 2 '跳过ID与编辑列
Dim currenttextbox As TextBox
currenttextbox = e.Item.Cells(i).Controls(0)
Dim colvalue As String = currenttextbox.Text
If i = numcols - 3 And PriceIsNotNumberic(colvalue) Then Exit Sub
mycommand.Parameters(cols(i - 1)).Value = colvalue
Next
conn.Open()
Try
mycommand.ExecuteNonQuery()
Lblmessage.Text = "编号为<b>" _
& CInt(mycommand.Parameters("@id").Value) _
& "</b>的记录已被更新!"
Lblmessage.ForeColor = Color.Green
mydatagrid.EditItemIndex = -1
Catch exp As SqlException
Lblmessage.Text = "错误:修改记录失败,请检查输入信息是否正确!"
Lblmessage.ForeColor = Color.Red
End Try
conn.Close()
grid_bind()
End Sub