嗨,我有一个 500 行的 excel 表,我想将该表上传到服务器上并将其数据插入到 sqlserver,并且我创建了名为 excel 的表,具有与 excel 表相同的列,数据需要存储到此表在上传 Excel 表时,当我只想检索一行时,我只想显示该行,这怎么可能,谁能告诉我?我不想使用 ms 访问和 oledb 连接,我有在我的项目中使用了 Sql server 2005.. 我试过这样,请告诉我错误在哪里............
protected void btnSend_Click(object sender, EventArgs e)
{
con.Open();
String strConnection = "user id=sa;pssword=E@2013;Data Source=EKTHA-3D34;Initial Catalog=Ektha;Integrated Security=True";
string path = fileuploadExcel.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";
string excelConnectionString = "user id=sa;password=E@2013;Data Source=EKTHA-3D34;Persist Security Info=False";
//Create Connection to Excel work book
SqlConnection excelConnection =new SqlConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
SqlCommand cmd = new SqlCommand("Select * from [Sheet1$]",excelConnection);
excelConnection.Open();
SqlDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "PayDescription";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}
}
}