1个回答
展开全部
定义一个数据库连接
Dim con As New SqlConnection("workstation id=计算机名;packet size=4096;user id=sa;data source=.;persist security info=False;initial catalog=数据库名")
对数据库插入
Dim incom As New SqlCommand("insert into 表名values(@id,@name,@password,@depart,@class)", con)
incom.Parameters.Add("@id", Me.idtb.Text)
incom.Parameters.Add("@name", Me.nametb.Text)
incom.Parameters.Add("@password", Me.passwordtb.Text)
incom.Parameters.Add("@depart", Me.departtb.Text)
incom.Parameters.Add("@class", Me.classtb.Text)
con.Open()
incom.ExecuteNonQuery()
con.Close()
MsgBox("insert good")
Me.DataGrid1.Refresh()
删除数据库项
Dim deleteEMP As SqlClient.SqlCommand = New SqlClient.SqlCommand("delete from 表名 where 列名 = '" & checkcb.Text & "'", conn)
result = deleteEMP.ExecuteNonQuery()
conn.Close()
Me.DataGrid1.Refresh()
MsgBox("delete good")
对数据库更新
Dim upcom As New SqlCommand("update 表明set Stu_name=@name,Stu_password=@password,Stu_depart=@depart,Stu_class=@class where Stu_id=@id", con)
upcom.Parameters.Add("@id", Me.idtb.Text)
upcom.Parameters.Add("@name", Me.nametb.Text)
upcom.Parameters.Add("@password", Me.passwordtb.Text)
upcom.Parameters.Add("@depart", Me.departtb.Text)
upcom.Parameters.Add("@class", Me.classtb.Text)
con.Open()
upcom.ExecuteNonQuery()
con.Close()
MsgBox("update good")
Dim con As New SqlConnection("workstation id=计算机名;packet size=4096;user id=sa;data source=.;persist security info=False;initial catalog=数据库名")
对数据库插入
Dim incom As New SqlCommand("insert into 表名values(@id,@name,@password,@depart,@class)", con)
incom.Parameters.Add("@id", Me.idtb.Text)
incom.Parameters.Add("@name", Me.nametb.Text)
incom.Parameters.Add("@password", Me.passwordtb.Text)
incom.Parameters.Add("@depart", Me.departtb.Text)
incom.Parameters.Add("@class", Me.classtb.Text)
con.Open()
incom.ExecuteNonQuery()
con.Close()
MsgBox("insert good")
Me.DataGrid1.Refresh()
删除数据库项
Dim deleteEMP As SqlClient.SqlCommand = New SqlClient.SqlCommand("delete from 表名 where 列名 = '" & checkcb.Text & "'", conn)
result = deleteEMP.ExecuteNonQuery()
conn.Close()
Me.DataGrid1.Refresh()
MsgBox("delete good")
对数据库更新
Dim upcom As New SqlCommand("update 表明set Stu_name=@name,Stu_password=@password,Stu_depart=@depart,Stu_class=@class where Stu_id=@id", con)
upcom.Parameters.Add("@id", Me.idtb.Text)
upcom.Parameters.Add("@name", Me.nametb.Text)
upcom.Parameters.Add("@password", Me.passwordtb.Text)
upcom.Parameters.Add("@depart", Me.departtb.Text)
upcom.Parameters.Add("@class", Me.classtb.Text)
con.Open()
upcom.ExecuteNonQuery()
con.Close()
MsgBox("update good")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询