datagridview 批量更新问题
小弟初学C#!跪求大哥大姐指教:数据库连接
SqlDataAdapter sda = new SqlDataAdapter("select RveID,Inno,InComeNo,InComeName,InAmont from Revenue",conn);
SqlCommandBuilder db = new SqlCommandBuilder(sda);
DataTable dt=new DataTable();
DataSet ds = new DataSet();
sda.Fill(ds);
DataRow myrow = ds.Tables[0].NewRow();
myrow["RveID"] = "1";
myrow["Inno"] = "20";
myrow["InComeNo"] = "1211111";
myrow["InComeName"] = "pangyb";
myrow["InAmont"] = "10";
ds.Tables[0].Rows.Add(myrow);
sda.Update(ds);
以上代码可以批量更新DataGridView,
问:如果将 myrow["RveID"]=变量;应该怎么做呢?
string val = "";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (j == 0)
{
int rows = i + 1;
val = rows.ToString();
}
else
{
val = this.dataGridView1.Rows[i].Cells[j].Value.ToString();
}
MessageBox.Show(val);
}
}
以上代码可以动态的获得给行各列的值
再问:怎样将这些各行的值分别赋值给myrow["RveID"] myrow["Inno"] myrow["InComeNo"] myrow["InComeName"] myrow["InAmont"]
[ 本帖最后由 plm010 于 2010-4-23 02:58 编辑 ]