|
Hi friends i need to import data from Excel file to sql server database. i got code for importing data from Excel to datagrid now i need to push the data to server database.
The code i got is..
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("/forum//ExcelData.xls") + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM MyRange1 ", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
OleDbCommandBuilder custCB = new OleDbCommandBuilder(objAdapter1);
objAdapter1.SelectCommand = objCmdSelect;
DataSet objDataset1 = new DataSet();
objAdapter1.AcceptChangesDuringFill =false;
objAdapter1.Fill(objDataset1, "Sample1");
DataGrid2.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid2.DataBind();
objConn.Close();
pl help me to push data from datagrid2 to server table called "Projects".
mancy.
|
|
|
Hi!
I m also working on the same concept. Did u finish importing the data to SQL server??? Can u pls guide me in this since I m a beginner, a student currently working on this project....Plzzzzzzzz help me!!! I want to know how to read data from a particular excelsheet when more than one exists in an excel workbook??? Plz help! Thanks a lot!!!
Regards,
Yukta.
|
|
|
hi try this code..
private void DataGrid2_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string sconnection="Provider=SQLOLEDB;data source=DEVELOPMENT;Initial catalog=ProjMgmt;User Id=ProjMgmt;password=priya;";
OleDbConnection obj=new OleDbConnection(sconnection);
obj.Open();
OleDbCommand objCmdsel=new OleDbCommand("SELECT * FROM Projects",obj);
OleDbDataAdapter objAdapt1=new OleDbDataAdapter();
OleDbCommandBuilder cust=new OleDbCommandBuilder(objAdapt1);
objAdapt1.SelectCommand=objCmdsel;
objAdapt1.Fill(ds,"Projects");
DataTable dbTable = ds.Tables["Projects"];
DataRow dbRow = dbTable.NewRow();
dbRow["UserID"] = Convert.ToString(e.Item.Cells[0].Text);
dbRow["ProjName"] =Convert.ToString(e.Item.Cells[1].Text);
dbRow["ProjStartDate"] =Convert.ToDateTime(e.Item.Cells[2].Text);
dbRow["ProjEndDate"] =Convert.ToDateTime(e.Item.Cells[3].Text);
dbTable.Rows.Add(dbRow);
// Update data source
objAdapt1.Update(ds,"Projects");
obj.Close();
}
|
|
|
|
|
|
|
|