VB.Net学习笔记(一)

1、 数据库连接

在app.config中写入连接字符串,可通过DataGridView1的任务建立,添加项目数据源!

<connectionStrings>

        <add name="根命名空间.My.MySettings.YarnStoreConnectionString"

            connectionString="Data Source=192.168.0.2\home,7789(端口);Initial Catalog=根命名空间;Persist Security Info=True;User ID=sa;Password=power"

            providerName="System.Data.SqlClient" />

</connectionStrings>

××××

<connectionStrings>

        <add name="ttttt.My.MySettings.shanhuaConnectionString" connectionString="Data Source=192.168.0.5;Initial Catalog=shanhua;User ID=sa;Password=&quot;qaz123=-&quot;"

            providerName="System.Data.SqlClient" />

    </connectionStrings>

2、 用代码连接数据库到DataGridView

Dim strsql AsString

Strsql=“sql语句”

Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strsql, My.Settings.YarnStoreConnectionString)

Dim dt AsNew Data.DataSet

da.Fill(dt, "p_dj")

DataGridView1.DataSource = dt

DataGridView1.DataMember = "p_dj"

×××××

也可以通过DataGridView1的任务建立——

代码:

Dim ccc AsNew shanhuaDataSet.DepartmentDataTable

DepartmentTableAdapter.Fill(ccc)

DataGridView1.DataSource = ccc

其中FILL函数为shanhuaDataSet.xsd中设置的查询函数,可以灵活设置!

3、 动态生成控件代码,并添加控件响应事件

Dim bbb AsNew DataGridView(控件类型)

bbb.Top = 200

bbb.Left = 200

bbb.Height = 200

bbb.Width = 300

Me.Controls.Add(bbb)

AddHandler bbb.MouseUp, AddressOf MouseUp1

——bbb.MouseUp为该控件的系统事件;MouseUp1为事件过程名称

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页