记录的方法 

Partial Class Default8
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

'查询记录的方法 
'定义()
Dim MyConn As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand

MyConn = New Data.SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=cz2008")

Dim sqlstr As String
sqlstr = "Select * from T_bmddm where bmddm  like " + "'%" + TextBox1.Text + "%'"
Page.Response.Write(sqlstr)

MyComm = New Data.SqlClient.SqlCommand(sqlstr, MyConn)
MyConn.Open()

If MyConn.State = 1 Then
Label1.Text = "The Connection State is: " & MyConn.State & " - Connection Succeeded"
Else
Label1.Text = "The Connection State is: " & MyConn.State & " - Connection Failed"
End If

Dim reader As Data.SqlClient.SqlDataReader = MyComm.ExecuteReader
'Authors.DataSource = reader


' Page.Response.Write(MyComm.ExecuteReader.Item(0))
Authors.DataSource = MyComm.ExecuteReader
Authors.DataBind()

Page.Response.Write(MyComm.Connection.DataSource)
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
'删除记录的方法
Dim MyConn As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand
MyConn = New Data.SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=cz2008")
Dim sqlstr As String
sqlstr = "delete from T_bmddmwhere bmddm =" + " '" + TextBox1.Text + "'"
MyComm = New Data.SqlClient.SqlCommand(sqlstr, MyConn)
MyConn.Open()
If MyConn.State = 1 Then
Label1.Text = "The Connection State1 is: " & MyConn.State & " - Connection Succeeded"
Else
Label1.Text = "The Connection State1 is: " & MyConn.State & " - Connection Failed"
End If
MyComm.CommandText = sqlstr
MyComm.ExecuteNonQuery()
MsgBox("信息删除成功!", 0, "提示")
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
'实用session查询记录的方法
'通过Page.Session临时记录变量
Dim MyConn As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand

MyConn = New Data.SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=cz2008")

Dim sqlstr As String
Dim aa As String
Page.Session("aa") = TextBox1.Text
Page.Response.Write(Page.Session("aa"))
sqlstr = "Select * from T_bmddm where bmddm  like " + "'%" + TextBox1.Text + "%'"
Page.Response.Write(sqlstr)

MyComm = New Data.SqlClient.SqlCommand(sqlstr, MyConn)
MyConn.Open()

If MyConn.State = 1 Then
Label1.Text = "The Connection State is: " & MyConn.State & " - Connection Succeeded"
Else
Label1.Text = "The Connection State is: " & MyConn.State & " - Connection Failed"
End If
Authors.DataSource = MyComm.ExecuteReader
Authors.DataBind()

End Sub
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

'插入记录的方法
Dim sql As String
Dim MyConn As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand
MyConn = New Data.SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=cz2008")
Dim tBmddm, tbmd, txzqhdm, taddr, ttel, tlxr, tbmdcc, tzslbdm, tpassword, tnote, ttag, tbmdkl, tfirst_sn, tlast_sn As String

tBmddm = Bmddmtxt.Text
tbmd = bmdtxt.Text
txzqhdm = xzqhdmtxt.Text
taddr = addrTxt.Text
ttel = telTxt.Text
tlxr = lxrTxt.Text
tbmdcc = bmdccTxt.Text
tzslbdm = zslbdmTxt.Text
tpassword = passwordTxt.Text
tnote = noteTxt.Text
ttag = tagTxt.Text
tbmdkl = bmdklTxt.Text
tfirst_sn = first_snTxt.Text
tlast_sn = last_snTxt.Text

sql = "insert into T_bmddm(Bmddm,bmd,xzqhdm,addr,tel,lxr,bmdcc,zslbdm,password,note,tag,bmdkl,first_sn,last_sn)  values (" + tBmddm + "," + tbmd + "," + txzqhdm + "," + taddr + "," + ttel + "," + tlxr + "," + tbmdcc + "," + tzslbdm + "," + tpassword + "," + tnote + "," + ttag + "," + tbmdkl + "," + tfirst_sn + "," + tlast_sn + ")"
MyComm = New Data.SqlClient.SqlCommand(sql, MyConn)
MyConn.Open()
MyComm.ExecuteNonQuery()
MyConn.Close()
MsgBox("信息添加成功!", 0, "提示")

End Sub

Protected Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click
'修改记录的方法


Dim sql As String
Dim tBmddm, tbmd, txzqhdm As String

tBmddm = Bmddmtxt.Text
tbmd = bmdtxt.Text
txzqhdm = xzqhdmtxt.Text
Dim MyConn As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand
MyConn = New Data.SqlClient.SqlConnection("server=localhost;uid=sa;pwd=;database=cz2008")
sql = "Update T_bmddm Set bmd=" + tbmd + " Where bmddm=" + tBmddm
MyComm = New Data.SqlClient.SqlCommand(sql, MyConn)
MyComm = New Data.SqlClient.SqlCommand(sql, MyConn)
MyConn.Open()
MyComm.ExecuteNonQuery()
MyConn.Close()
MsgBox("信息修改成功!", 0, "提示")
End Sub
End Class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值