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;… Continue reading

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… Continue reading

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 ExecuteReader, ExecuteNonQuery and ExecuteScalar.

ExecuteReader : Use for accessing data. It provides a forward-only, read-only, connected record-set. ExecuteNonQuery : Use for data manipulation, such as Insert, Update, Delete. ExecuteScalar : Use for retrieving 1 row 1 col. value., i.e. Single value. eg: for retrieving aggregate function. It is faster than other ways of retrieving… Continue reading

Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?

In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the dataset. There are important differences between them. A recordset looks like a single table. If a recordset is to contain data from multiple database tables, it must use a JOIN query, which assembles the data… Continue reading