VB.net dataset用法和datagridview
VS2010的我在form1的窗口添加了dataset和datagridview两个控件dataset里面创建一个表table1,table1有6列("姓名","语文",...
VS 2010的
我在form1的窗口添加了dataset 和 datagridview 两个控件
dataset里面创建一个表table1,table1有6列 ("姓名" ,"语文","数学","英语","综合","准考证号")
name caption columname全都改成对应的中文
datagridview 指向dataset datagridview1.source=dataset1
可是datagridview没有显示任何东西。
我想问一下datagidview1出什么问题?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim row1 As DataRow
row1 = table1.NewRow
row1("姓名") = "Tom"
row1("语文") = 121
row1("数学") = 145
row1("英语") = 134
row1("综合") = 127
row1("准考证号") = "032158"
table1.Rows.Add(row1)
End Sub 展开
我在form1的窗口添加了dataset 和 datagridview 两个控件
dataset里面创建一个表table1,table1有6列 ("姓名" ,"语文","数学","英语","综合","准考证号")
name caption columname全都改成对应的中文
datagridview 指向dataset datagridview1.source=dataset1
可是datagridview没有显示任何东西。
我想问一下datagidview1出什么问题?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim row1 As DataRow
row1 = table1.NewRow
row1("姓名") = "Tom"
row1("语文") = 121
row1("数学") = 145
row1("英语") = 134
row1("综合") = 127
row1("准考证号") = "032158"
table1.Rows.Add(row1)
End Sub 展开
3个回答
展开全部
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
cnn = New ADODB.Connection
rs = New ADODB.Recordset
cnn.ConnectionString = "Driver={SQL Server};Server=数据库IP地址;uid=用户名;pwd=密码;DataBase=数据库名称"
cnn.Open()
Dim sql As String
sql = "Select * from 表名"
rs.Open(sql, cnn, 3, 1)
Dim da As New System.Data.OleDb.OleDbDataAdapter
Dim ds As New DataSet
da.Fill(ds, rs, 1)
DataGridView1.DataSource = ds.Tables(0)
展开全部
Public Function SUB_select(ByVal x As OleDb.OleDbConnection, ByVal y As DataGridView, ByVal z As String)
Try
Dim NewDataTable As New DataTable
Dim NewSql As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(z, x)
NewSql.Fill(NewDataTable)
y.DataSource = Nothing
y.DataSource = NewDataTable
Return True
Catch ex As Exception
MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
End Function
追问
我想问的是datagridview1这个控件怎么把我建立的这个基本表table1的信息显示出来
追答
绑定数据
Datagridview1.DataSource=Table1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
datagridview1.source=DataSet1.Tables(0)'如果只有一个表
或者datagridview1.source=DataSet1.Tables(“table1”)
或者datagridview1.source=DataSet1.Tables(“table1”)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询