代码哪里错了?
我用了两个按钮,做了简单的查询数据库和更新到数据库操作,但出现了错误,小弟水平有限,尝试了好久,仍无法解决.
请各位大哥帮帮忙,小弟感激不尽.
出现以下错误:
未处理的“System.MissingMemberException”类型的异常出现在 microsoft.visualbasic.dll 中。
其他信息: 未找到类型“SqlCommand”的公共成员“Paremeters”。
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strConn As String = "Data source=(local);initial catalog=hero;uid=sa;pwd=;"
Dim cn As New SqlConnection(strConn)
cn.Open()
Dim strInsertSQL As String
Dim strSelectSQL As String
strInsertSQL = "insert into hero(攻击力平均值,生命值,魔法值,护甲,力量,敏捷,智力,英雄名字,英雄LV)values(@攻击力平均值,@生命值,@魔法值,@护甲,@力量,@敏捷,@智力,@英雄名字,@英雄LV)"
Dim cmd As New SqlCommand(strInsertSQL, cn)
Dim cmd2 = New SqlCommand("select count(*) from hero where 英雄名字='" & ComboBox1.Text & "'" & " and 英雄LV ='" & ComboBox2.Text & "'", cn)
Dim cmd3 = New SqlCommand("select * from hero where 英雄名字=@name and 英雄LV=@LV", cn)
If cmd2.ExecuteScalar = 1 Then
MsgBox("输入的英雄名字已存在!重新输入")
ComboBox1.Focus()
Exit Sub
End If
'Else
cmd.Parameters.Add("@攻击力平均值", SqlDbType.VarChar)
cmd.Parameters.Add("@生命值", SqlDbType.Int)
cmd.Parameters.Add("@魔法值", SqlDbType.Int)
cmd.Parameters.Add("@护甲", SqlDbType.TinyInt)
cmd.Parameters.Add("@力量", SqlDbType.TinyInt)
cmd.Parameters.Add("@敏捷", SqlDbType.TinyInt)
cmd.Parameters.Add("@智力", SqlDbType.TinyInt)
cmd.Parameters.Add("@英雄名字", SqlDbType.VarChar)
cmd.Parameters.Add("@英雄LV", SqlDbType.TinyInt)
cmd.Parameters("@攻击力平均值").Value = TextBox1.Text
cmd.Parameters("@生命值").Value = TextBox2.Text
cmd.Parameters("@魔法值").Value = TextBox3.Text
cmd.Parameters("@护甲").Value = TextBox4.Text
cmd.Parameters("@力量").Value = TextBox5.Text
cmd.Parameters("@敏捷").Value = TextBox6.Text
cmd.Parameters("@智力").Value = TextBox7.Text
cmd.Parameters("@英雄名字").Value = ComboBox1.Text
cmd.Parameters("@英雄LV").Value = ComboBox2.Text
cmd.ExecuteNonQuery()
cn.Close()
MsgBox("Save OK!")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strConn As String = "Data source=(local);initial catalog=hero;uid=sa;pwd=;"
Dim cn As New SqlConnection(strConn)
Dim cmd3 = New SqlCommand("select * from hero where 英雄名字=@name and 英雄LV=@LV", cn)
cmd3.Paremeters.add("@name", SqlDbType.VarChar)
cmd3.Paremeters.add("@LV", SqlDbType.TinyInt)
cmd3.Parameters("@name").Value = ComboBox1.Text
cmd3.Parameters("@LV").Value = ComboBox2.Text
cn.Open()
Dim rdhero As SqlDataReader = cmd3.ExecuteReader()
rdhero.Read()
TextBox1.Text = rdhero.GetString(0)
TextBox2.Text = rdhero.GetString(1)
TextBox3.Text = rdhero.GetString(2)
TextBox4.Text = rdhero.GetString(3)
TextBox5.Text = rdhero.GetString(4)
TextBox6.Text = rdhero.GetString(5)
TextBox7.Text = rdhero.GetString(6)
rdhero.Close()
cn.Close()
End Sub
[解决办法]
cmd3.Parmeters未赋值
[解决办法]