谁能帮我翻译一下这段VB代码
Imports System.Data.SqlClient
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mycon As SqlConnection
mycon = New SqlConnection
mycon.ConnectionString = "initial catalog=1210500140;data source=.;integrated security=true;"
Dim sql As String
sql = "select * from T_teacher where TeacherName like '%" & TextBox1.Text & "%'"
Dim mycommand As SqlCommand
mycommand = New SqlCommand
mycommand.CommandText = sql
mycommand.Connection = mycon
Dim mydataadapt As SqlDataAdapter
mydataadapt = New SqlDataAdapter
mydataadapt.SelectCommand = mycommand
Dim mydataset As DataSet
mydataset = New DataSet
mycon.Open()
mydataadapt.Fill(mydataset)
DataGrid1.DataSource = mydataset.Tables.Item(0)
' MessageBox.Show("success")
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
窗口如图,连接了一个数据库,我想仿照建一个类似的,但是不知道这些代码每句什么意思,按钮都怎么连接的,求大神!!! 展开
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mycon As SqlConnection
mycon = New SqlConnection
mycon.ConnectionString = "initial catalog=1210500140;data source=.;integrated security=true;" ‘连接数据库的参数
Dim sql As String
sql = "select * from T_teacher where TeacherName like '%" & TextBox1.Text & "%'"
’从数据库里查找T_teacher表teacherName中含有Textbox1(就是你看到让你输如查询信息的那个框)关键字的条目
Dim mycommand As SqlCommand
mycommand = New SqlCommand
mycommand.CommandText = sql 数据读取的方式就是上面sql所规定的
mycommand.Connection = mycon 数据连接用上面的mycon执行
Dim mydataadapt As SqlDataAdapter
mydataadapt = New SqlDataAdapter 建立一个数据转换
mydataadapt.SelectCommand = mycommand 数据读取的参数为mycommand
Dim mydataset As DataSet
mydataset = New DataSet 定义一个数据表
mycon.Open() 打开数据库连接
mydataadapt.Fill(mydataset) 将搜索到的数据填充到mydataset这个容器里
DataGrid1.DataSource = mydataset.Tables.Item(0)
datagrid1的数据源=我搜索到的数据里面(mydataset)的第一组数据
' MessageBox.Show("success")
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
第一段能再详细点吗?button1是哪个按钮?这个是把数据库和按钮相连还是和啥相连?
Dim mycommand As SqlCommand mycommand 是啥?
BUtton1 就是那个查询按钮啊,按钮事件,就是按钮一点击,就触发查询数据库并显示到datagird这个事件。dim mycommand as sqlcommand 就是定义mycommand这个变量是SQL数据库类型的命令。
进口System.Data.SqlClient
公开课Form2
私人子Button1_Click(按值传递发送方系统。对象,按值传递e System.EventArgs)处理Button1.Click
暗mycon SqlConnection
mycon =新SqlConnection
mycon。ConnectionString = " =初始目录= 1210500140;数据源。,综合安全= true;”
昏暗的sql字符串
sql = " select *从T_teacher TeacherName像“%”& TextBox1。文本和“%”
暗mycommand SqlCommand
mycommand =新SqlCommand
mycommand。CommandText = sql
mycommand。连接= mycon
暗mydataadapt SqlDataAdapter
mydataadapt =新SqlDataAdapter
mydataadapt。SelectCommand = mycommand
昏暗的mydataset作为数据集
mydataset =新数据集
mycon.Open()
mydataadapt.Fill(mydataset)
DataGrid1。数据源= mydataset.Tables.Item(0)
“MessageBox.Show(“成功”)
终止子
私人子TextBox1_TextChanged(按值传递发送方系统。对象,按值传递e System.EventArgs)处理TextBox1.TextChanged
终止子
进口system.data.sqlclient
public class Form2
私人_ Button1 Click(ByVal发射器子系统为对象,即一个。点击system.eventargs Button1)处理。
昏暗的mycon SqlConnection。
mycon = new SqlConnection
mycon.connectionstring = ";初始目录= 1210500140;数据源=。= true;综合安全;";
sql字符串
SQL SELECT * FROM = ";t _教师在teachername样为";&;这文本。&;%的";";
昏暗的mycommand作为SqlCommand
mycommand =新SqlCommand
mycommand.commandtext = SQL
连接= mycon mycommand。
昏暗的mydataadapt SqlDataAdapter。
mydataadapt SqlDataAdapter =新
mydataadapt.selectcommand = mycommand
mydataset昏暗的数据集。
mydataset =新的数据集
mycon.open()
mydataadapt.fill(mydataset)
datagrid1.datasource = mydataset.tables.item(0)
(成功messagebox.show ";";)
End Sub
这_ TextChanged事件私人子系统对象,如一个发射机。textbox1.textchanged E作为system.eventargs)处理
End Sub