'定义参数
Dim id As New SqlClient.SqlParameter("@id", SqlDbType.Int, 4)
Dim name As New SqlClient.SqlParameter("@name", SqlDbType.VarChar, 10)
Dim sex As New SqlClient.SqlParameter("@sex", SqlDbType.Char, 2)
Dim xl As New SqlClient.SqlParameter("@xl", SqlDbType.VarChar, 4)
Dim sqlstr As String
sqlstr = "insert into 基本信息表(编号,姓名,性别,学历) values(@id,@name,@sex,@xl)"
'将参数集加到定义好的命令对象中
mycom.Parameters.Add(id)
mycom.Parameters.Add(name)
mycom.Parameters.Add(sex)
mycom.Parameters.Add(xl)
'为参数赋值
id.Value = CInt(tbid.Text)
name.Value = tbname.Text
If rb1.Checked = True Then
sex.Value = "男"
Else
sex.Value = "女"
End If
xl.Value = Cbbxl.Text
If mycon.State = ConnectionState.Closed Then mycon.Open()
Try
remycom(sqlstr).ExecuteNonQuery()
Catch sqlex As SqlClient.SqlException
MsgBox("数据库信息:" & sqlex.Message)
Finally
mycon.Close()
End Try
sqlstr = "select * from 基本信息表"
dset.Clear()
If mycon.State = ConnectionState.Closed Then mycon.Open()
redset(sqlstr, "基本信息表")
mycon.Close()
错误提示
数据库信息:必须声明变量"@id"
请问为什么会出现这种错误
应该怎么改
谢谢