如何把datagrid中数据-dataset中数据导入SQL数据库

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1、 如何把datagrid中数据导入SQL数据库? 

if (this.DataGrid1.Items.Count > 0)
{
foreach (DataGridItem oDataGridItem in DataGrid1.Items)
{
string strTheHour = oDataGridItem.Cells[0].Text.ToString();
string sql = "Insert into Temp(TheHour) values(" + strTheHour + ")";
Connect.ExecuteSql(sql);

}
}




2、如何在dataset中数据插入SQL数据库

SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);
try
{
SqlDataAdapter myda = new SqlDataAdapter(sql, conn);
DataSet myds = new DataSet();
conn.Close();
conn.Open();
myda.Fill(myds, "" +strTable+ "");

foreach (System.Data.DataRow row in myds.Tables[0].Rows)
{
string strTheHour = row["TheHour"].ToString().Trim();
string sql = "Insert into Temp(TheHour) values(" + strTheHour + ")";
Connect.ExecuteSql(sql);
}
this.DataGrid1.DataSource = myds.Tables["" + strTable + ""].DefaultView;
this.DataGrid1.DataBind();
conn.Close();
this.Response.Write(" ");
}
catch (Exception exc)
{
conn.Close();
string s = exc.ToString();
}

相关文档
最新文档