Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
First I'm filling my dataset through sqldataadapter.
then I'm adding a Datarow in dataset.
My question: How do I make new datarow as first row of dataset.
Posted

Hi Sant

Try the following

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[urconnectionstring].ConnectionString.ToString());
            SqlCommand sqlCom = new SqlCommand(urQuery);
            sqlCom.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(sqlCom.CommandText, con);
            DataSet dsEmp = new DataSet();
            da.Fill(dsEmp);
            if (dsEmp.Tables.Count > 0)
            {
                if (dsEmp.Tables[0] != null && dsEmp.Tables[0].Rows.Count>0)
                {
                    
                    dsEmp.Tables[0].Rows.InsertAt(dsEmp.Tables[0].NewRow(), 0);
                }
            }
            GridView1.DataSource = dsEmp.Tables[0];
            GridView1.DataBind();



Hope this helps
 
Share this answer
 
Comments
Prince Antony G 2-Dec-11 2:00am    
try this..my 5+
Sant Osha 2-Dec-11 2:32am    
thank you very much Srimanch
Hi,

There is a property called InsertAt which will insert the datarow at the specified position. But make sure that the poistion is within in the limits of max rows count

Eg:
dt.Rows.InsertAt(yourDataRow, 0);


Hope this helps
 
Share this answer
 
v2
Comments
Sant Osha 2-Dec-11 0:48am    
Srimanch ..this is not working

sqldataadpater da=new sqldataadpater ();
DataSet ds = new DataSet();
da.fill(ds);

DataRow dr = ds.Tables[0].Rows.InsertAt(dr, 0);
ds.Tables[0].Rows.Add(dr);


this is not working..
help me..
sriman.ch 2-Dec-11 1:28am    
is it throwing any error ? Is ds is filled with data? check this and let me know ....
Sant Osha 2-Dec-11 2:33am    
thank you very much Srimanch
try this

ds.Tables[0].Rows.InsertAt(ds.Tables[0].NewRow(), 0);



check this Click here
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900