c#怎么连接sql数据库并将实时获取到的数据添加到数据库里面去?

2025-01-24 14:01:25
推荐回答(1个)
回答1:

string filepath = "d:\\signup.xlsx";
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
OleDbConnection conn = new OleDbConnection(strCon);
OleDbCommand comm = conn.CreateCommand();try
{
conn.Open();

string qry = string.Empty;
qry = "insert into [Sheet1$] values(1,2)";
comm.CommandText = qry;

comm.ExecuteNonQuery();

}
catch (Exception e)
{
}