C#里面添加数据到数据库的代码怎么写?

2024-10-30 20:43:07
推荐回答(4个)
回答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)
{
}

回答2:

自己传sql语句

回答3:

先获取,在写sql

回答4:

网上找c# 数据库 CURD操作