我正在使用Visual Studio Express 2012制作系统并使用我认为已经在visual studio中使用的Microsoft SQL Server。我的问题是,当我试图运行我的系统时,会出现错误"运营商''''未定义类型'字符串'和' System.Windows.Forms.DataGridView'。"这是我的代码。
Imports System.Data.SqlClient
Public Class Registration
Dim cn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\user_PC\Desktop\For FYP\Computer Lab Requirement System\FYP3\FYP3\FYP.mdf;Integrated Security=True")
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Private Sub Registration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cmd.Connection = cn
End Sub
Private Sub btnRegisterL_Click(sender As Object, e As EventArgs) Handles btnRegisterL.Click
If txtIDL.Text <> "" And txtUsernameL.Text <> "" And txtPasswordL.Text <> "" Then
cn.Open()
cmd.CommandText = "update info set id = '" & txtIDL.Text & "',user = '" & txtUsernameL.Text & "',pass = '" & txtPasswordL.Text & "'where id = '" & Form1.DataGridView1 & "' "
cmd.ExecuteNonQuery()
cn.Close()
txtIDL.Text = ""
txtUsernameL.Text = ""
txtPasswordL.Text = ""
End If
End Sub
End Class
我很高兴,如果有人可以帮我解释并告诉我上面编码的错误。我是这个人的新手。谢谢。 :)
答案 0 :(得分:0)
You could hold the Primary Key of your data in your GridView in one of the columns and then use that in your query, instead of the below line that you have:
"'where id = '" & Form1.DataGridView1 & "' "