如:
DataTable dt = dsTable[0];
int cols = dtColumnscount;
int rows = dtRowscount;
for(int i = 0; i < rows; i ++)
{
for(int j = 0; j < cols; j ++)
{
//遍历每一行每一列;
if(j == cols - 1) //列索引为最后一列;
{
dtRows[i][j] = "你要赋的值!";
}
}
}这个是我写的测试代码,,能做到你想的结果
string connStr = "server=;database=pubs;user=sa;pwd=sa;";
string sql = "select from jobs";
SqlDataAdapter sqlda = null;
DataTable dt=new DataTable();
using (SqlConnection sqlcon = new SqlConnection(connStr))
{
using (SqlCommand sqlcom = new SqlCommand(sql, sqlcon))
{
sqlda = new SqlDataAdapter(sqlcom);
sqldaFill(dt);
DataTable tempDT = dtClone();//克隆表结构
for (int i = 3; i < 8; i++)
{
tempDTImportRow(dtRows[i]);//将所需要的数据导入表中
}
}
}/// <summary>
/// 修改数据表DataTable某一列的类型和记录值(正确步骤:1克隆表结构,2修改列类型,3修改记录值,4返回希望的结果)
/// </summary>
/// <param name="argDataTable">数据表DataTable</param>
/// <returns>数据表DataTable</returns>
private DataTable UpdateDataTable(DataTable argDataTable)
{
DataTable dtResult = new DataTable();
//克隆表结构
dtResult = argDataTableClone();
foreach (DataColumn col in dtResultColumns)
{
if (colColumnName == "age")
{
//修改列类型
colDataType = typeof(String);
}
}
foreach (DataRow row in argDataTableRows)
{
DataRow rowNew = dtResultNewRow();
rowNew["MemberId"] = row["MemberId"];
rowNew["NickName"] = row["NickName"];
//修改记录值
rowNew["age"] = row["age"] + "岁";
dtResultRowsAdd(rowNew);
}
//返回希望的结果
return dtResult;
}
类似 你看看这个就是C#的装箱和拆箱了简单说就是值类型和引用类型之间的转换
----
装箱:dr[0] = "test";
----
拆箱:TextBox1Text = (string)dr[0];
----
由于装箱和拆箱比较费事,所以对于像dr[0]这样的object对象提供了ToString()方法的重载避免拆箱:TextBox1Text = dr[0]ToString();
----
TextBox1Text = dr[0]ToString();
dr[0]本来就是一个object对象而TextBox1Text是取的dr[0]的值,这个值是一个string类型
建议把所有checkbox 的值遍历,代码是这样的:
Dim datarow As DataRowdatarow = dsTables("Emp_base1")NewRow()
If dsTables("Emp_base1")ColumnsCount = 0 Then
For i As Integer = 1 To MeDataGridView1ColumnsCount - 1
dsTables("Emp_base1")ColumnsAdd(MeDataGridView1Columns(i)Name)
Next
End If
dsTables("Emp_base1")RowsClear()
For i As Integer = 0 To MeDataGridView1RowsCount - 1
If MeDataGridView1Rows(i)Cells(0)Value = True Then
For a As Integer = 0 To MeDataGridView1ColumnsCount - 2
Dim b = a + 1
datarow(a) = MeDataGridView1Rows(i)Cells(b)Value
Next
dsTables("Emp_base1")RowsAdd(datarow)
End If
NextDataTable dt = new DataTable();
int col = dtColumnsCount;
string[,] array = new string[dtRowsCount,col];
for (int i = 0; i < dtRowsCount; i++)
{
for (int j = 0; j < dtColumnsCount; j++)
{
array[i, j] = dtRows[i][j]ToString()ToUpper()Trim();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)