0

Excel から SQL Server データベースにデータをインポートしようとしています。しかし、実行するとすべてがアップロードされず、実行すると次のエラーが発生しました。

1 つ以上の必須パラメーターに値が指定されていません。

誰でも助けることができますか?これは私のコードです:

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();
}
4

0 に答える 0