我正在尝试将数据从 Excel 导入 SQL Server 数据库。但是当我运行它时,一切都没有上传,我运行它时出现了这个错误:
没有为一个或多个必需参数指定值。
任何人都可以帮忙吗?这是我的代码:
protected void Button1_Click1(object sender, EventArgs e)
{
String strConnection = "Data Source="";Initial Catalog="";Integrated Security=True";
//file upload path
string path = FileUpload1.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [ID],[StudentName],[CLass],[NRIC],[FixedAmount] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "StudentParticulars";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}