« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
|
统计 |
blog名称:小雨 日志总数:262 评论数量:1273 留言数量:15 访问次数:4674457 建立时间:2005年1月8日 |
| 
|
W3CHINA Blog首页 管理页面 写新日志 退出
[经验杂谈]vb.net 下listbox 数据邦定 |
小雨 发表于 2006/10/10 23:54:02 | Dim conn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand Dim adpt As SqlClient.SqlDataAdapter Dim rst As New DataSet Dim SplitSQL As String = "SELECT * FROM Orders WHERE (ShippedDate < '1996-7-17') "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ConnectToSql() End Sub Public Sub ConnectToSql()
' TODO: Modify the connection string and include any ' additional required properties for your database. conn.ConnectionString = "data source=(local);initial catalog=northwind;user id=sa;pwd=" Try conn.Open() MessageBox.Show("ok") adpt = New SqlClient.SqlDataAdapter(SplitSQL, conn) adpt.Fill(rst, "Orders")
ListBox1.DataSource = rst ListBox1.DisplayMember = "Orders.ShippedDate" ListBox1.ValueMember = "Orders.ShippedDate"
' Insert code to process data. Catch ex As Exception
MessageBox.Show("Failed to connect to data source " & ex.Message) Finally conn.Close() End Try End Sub
|
阅读全文(10105) | 回复(2) | 编辑 | 精华 |
回复:vb.net 下listbox 数据邦定 |
zj(游客)发表评论于2006/10/12 15:11:41 | Public Sub ConnectToSql()
' TODO: Modify the connection string and include any ' additional required properties for your database. conn.ConnectionString = "data source=(local);initial catalog=northwind;user id=sa;pwd=" Try conn.Open()
SplitSQL = SplitSQL.ToLower() MsgBox(SplitSQL.IndexOf("delete")) If SplitSQL.IndexOf("delete") = 0 Or SplitSQL.IndexOf("update") = 0 Then cmd.Connection = conn cmd.CommandText = SplitSQL cmd.ExecuteNonQuery() Else
' adpt = New SqlClient.SqlDataAdapter(SplitSQL, conn) adpt = New SqlClient.SqlDataAdapter adpt.SelectCommand = New SqlClient.SqlCommand(SplitSQL, conn) adpt.SelectCommand.Parameters.Add("@f", SqlDbType.Int, 3).Value = 3 adpt.Fill(rst, "Re") ListBox1.DataSource = rst ListBox1.DisplayMember = "Re.RegionID" ListBox1.ValueMember = "Re.RegionID" End If ' Insert code to process data. Catch ex As Exception MessageBox.Show("Failed to connect to data source " & ex.Message) Finally conn.Close() End Try End Sub
|
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除 |
回复:vb.net 下listbox 数据邦定 |
小雨发表评论于2006/10/11 0:04:19 | If SplitSQL.IndexOf("delete") = 0 Or SplitSQL.IndexOf("update") = 0 Then cmd.Connection = conn cmd.CommandText = SplitSQL cmd.ExecuteNonQuery() Else adpt = New SqlClient.SqlDataAdapter(SplitSQL, conn) adpt.Fill(rst, "Orders") ListBox1.DataSource = rst ListBox1.DisplayMember = "Orders.PASSENGERNAME" ListBox1.ValueMember = "Orders.PASSENGERNAME" End If
|
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除 |
» 1 »
|