How to import data from excel file into dataset and then SQL db?

OleDbConnection con = new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:/file.xls; Extended Properties=Excel 8.0; “); OleDbDataAdapter oadp1 = new OleDbDataAdapter(“Select * from [sheet1$] where Id >0″, con); DataSet ods1 = new DataSet(); oadp1.Fill(ods1, “Data”); DataSet Dds1 = new DataSet(); Dds1.Tables.Add(new DataTable(“NewData”)); Dds1.Tables[“NewData”].Columns.Add(new DataColumn(“Id”)); Dds1.Tables[“NewData”].Columns.Add(new DataColumn(“Name”)); for (int i = 0; i < ods1.Tables[“Data”].Rows.Count; i++) { DataRow row = Dds1.Tables[“NewData”].NewRow(); row[0] = ods1.Tables[“Data”].Rows[i][0]; row[1] = ods1.Tables[“Data”].Rows[i][1]; Dds1.Tables[“NewData”].Rows.Add(row); } SqlConnection con1 = new SqlConnection(“Password=123; Persist Security Info=True; User ID=sa; Initial Catalog=DB; Data Source=.;”); SqlDataAdapter adp = new SqlDataAdapter(“select * from CompanyData”, con1); SqlCommandBuilder scb = new SqlCommandBuilder(adp); adp.InsertCommand = scb.GetInsertCommand(true); adp.Update(Dds1, “CompanyData”);

Which namespace is used by ADO.NET?

The System.Data namespace consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.

How does we get records from 5 to 15 from a dataset of 100 records?

SqlConnection con=new SqlConnection (ConfigurationSettings.AppSettings["cons"]); SqlCommand cmd=new SqlCommand(“student”,con); SqlDataAdapter db=new SqlDataAdapter(); db.SelectCommand=cmd; cmd.CommandType=CommandType.StoredProcedure; DataSet ds = new DataSet(); db.Fill(ds,5,15,”student”); DataGrid1.DataSource=ds; DataGrid1.DataBind(); this will return the 10 rows of the result set. In the above code “student” is the name of the stored procedure.

Difference between Dataset and Recordset?

DataSet is an ADO.Net object and RecordSet is an ADO object. DataSet can be considered as a logical database as it has the capability to store more than one table and have relations maintained between the tables as in a relational database. Where as a RecordSet can hold only one table at a time. Dataset is based on disconnected architecture where as Recordset is based on connected architecture. Dataset is type safe where as Recordset is not. Dataset can contain different tables from different database whereas Recordset cannot. In dataset there is no concept of cursor types and lock type … Click here to continue reading.