DataTable 怎么给 DataSet 赋值 20
c#.net手动构造DataTable如:DataTabledt=newDataTable;DataSetds=newDataSet;ds=dt;我的意思是能不能dt包含...
c#.net
手动构造 DataTable
如:
DataTable dt = new DataTable;
DataSet ds = new DataSet;
ds=dt;
我的意思是 能不能 dt包含ds;
再对数据库操作。。。
因为我的DataTable是手动构造的,想放到DataSet里
(而不是ds.Tables.Add(dt);)
再转到DataTable
private void dataTable_init()
{
UserInfo[] ui = new UserInfo[4];
ui[0] = new UserInfo();
ui[0].no = "1";
ui[0].file = "姓名";
ui[0].text = "";
ui[1] = new UserInfo();
ui[1].no = "2";
ui[1].file = "年龄";
ui[1].text = "";
ui[2] = new UserInfo();
ui[2].no = "3";
ui[2].file = "学历";
ui[2].text = "";
ui[3] = new UserInfo();
ui[3].no = "4";
ui[3].file = "收入";
ui[3].text = "";
for (int i = 0 ; i<ui.Length ;i++)
{
DataRow anyRow = dataTable.NewRow();
anyRow[0] = ui[i].no;
anyRow[1] = ui[i].file;
anyRow[2] = ui[i].text;
dataTable.Rows.Add(anyRow);
}
怎么把dataTable放到dataset里???? 展开
手动构造 DataTable
如:
DataTable dt = new DataTable;
DataSet ds = new DataSet;
ds=dt;
我的意思是 能不能 dt包含ds;
再对数据库操作。。。
因为我的DataTable是手动构造的,想放到DataSet里
(而不是ds.Tables.Add(dt);)
再转到DataTable
private void dataTable_init()
{
UserInfo[] ui = new UserInfo[4];
ui[0] = new UserInfo();
ui[0].no = "1";
ui[0].file = "姓名";
ui[0].text = "";
ui[1] = new UserInfo();
ui[1].no = "2";
ui[1].file = "年龄";
ui[1].text = "";
ui[2] = new UserInfo();
ui[2].no = "3";
ui[2].file = "学历";
ui[2].text = "";
ui[3] = new UserInfo();
ui[3].no = "4";
ui[3].file = "收入";
ui[3].text = "";
for (int i = 0 ; i<ui.Length ;i++)
{
DataRow anyRow = dataTable.NewRow();
anyRow[0] = ui[i].no;
anyRow[1] = ui[i].file;
anyRow[2] = ui[i].text;
dataTable.Rows.Add(anyRow);
}
怎么把dataTable放到dataset里???? 展开
3个回答
展开全部
建议把所有checkbox 的值遍历,代码是这样的:
Dim datarow As DataRow
datarow = ds.Tables("Emp_base1").NewRow()
If ds.Tables("Emp_base1").Columns.Count = 0 Then
For i As Integer = 1 To Me.DataGridView1.Columns.Count - 1
ds.Tables("Emp_base1").Columns.Add(Me.DataGridView1.Columns(i).Name)
Next
End If
ds.Tables("Emp_base1").Rows.Clear()
For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
If Me.DataGridView1.Rows(i).Cells(0).Value = True Then
For a As Integer = 0 To Me.DataGridView1.Columns.Count - 2
Dim b = a + 1
datarow(a) = Me.DataGridView1.Rows(i).Cells(b).Value
Next
ds.Tables("Emp_base1").Rows.Add(datarow)
End If
Next
展开全部
With strBldSQL
.Append(" SELECT Jyuuyoudo_Code,detail FROM")
.Append(" SELECT * FROM")
.Append(" MASTER_IMPORT")
.Append(" ORDER BY B_ID ")
strSQLStmt = ""
strSQLStmt = strBldSQL.ToString
End With
' dataset作成
objDataset = dbconn.RunSelect(strSQLStmt)
' dataset
If objDataset.Tables("test").Rows.Count = 0 Then
MessageBox.Show("select is err!")
Else
End If
Me.Dgv_Jyuuyoudo.AutoGenerateColumns = False
Me.Dgv_Jyuuyoudo.DataSource = objDataset.Tables("test")
ds = CType(Me.Dgv_Jyuuyoudo.DataSource, DataTable)
数据库类:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
Public Class DBAdpClass_chiyy
Private cnn As New SqlConnection
'select home定义一个dataset
Public Function RunSelect(ByVal sql As String) As DataSet
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As New DataSet
cmd = New SqlCommand(sql, cnn)
If cnn.State = ConnectionState.Closed Then
cnn.Open()
End If
da = New SqlDataAdapter(cmd)
da.Fill(ds, "test")
Return ds
End Function
.Append(" SELECT Jyuuyoudo_Code,detail FROM")
.Append(" SELECT * FROM")
.Append(" MASTER_IMPORT")
.Append(" ORDER BY B_ID ")
strSQLStmt = ""
strSQLStmt = strBldSQL.ToString
End With
' dataset作成
objDataset = dbconn.RunSelect(strSQLStmt)
' dataset
If objDataset.Tables("test").Rows.Count = 0 Then
MessageBox.Show("select is err!")
Else
End If
Me.Dgv_Jyuuyoudo.AutoGenerateColumns = False
Me.Dgv_Jyuuyoudo.DataSource = objDataset.Tables("test")
ds = CType(Me.Dgv_Jyuuyoudo.DataSource, DataTable)
数据库类:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Sql
Public Class DBAdpClass_chiyy
Private cnn As New SqlConnection
'select home定义一个dataset
Public Function RunSelect(ByVal sql As String) As DataSet
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As New DataSet
cmd = New SqlCommand(sql, cnn)
If cnn.State = ConnectionState.Closed Then
cnn.Open()
End If
da = New SqlDataAdapter(cmd)
da.Fill(ds, "test")
Return ds
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DataTable dt = new DataTable;
DataSet ds = new DataSet;
ds.Tables.Add(dt);
DataSet ds = new DataSet;
ds.Tables.Add(dt);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询