Click here to Skip to main content
15,886,699 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code is for adding new row in gridview.when i write values in text box and press button then it will add a row in gridview.on pressing button row is added but at the top of the table i want it at the end of the table...
tell me how to do that



private void AddNewRecord(string ID, string Name, string qty, string type, string desc, string model, string sn, string tag, string cty, string node, string ip, string fip, string pro, string ram, string hd, string rmana, bool isUpdate)
{
SqlConnection connection = new SqlConnection(connstring);
string sqlStatement = string.Empty;

if (!isUpdate)
{
sqlStatement = "INSERT INTO ['ISB VAS Nodes$']" +
"(ID,RackName,QTY,Type,[Desc],Model,SN,AssetTag,City,NodeName,IPAddress,FloatIP,Processors,RAM,HardDisks,RAIDManager)" +
"VALUES (@ID,@RackName,@qty,@type,@desc,@model,@sn,@AssetTag,@city,@NodeName,@IPAddress,@FloatIP,@Processors,@ram,@HardDisks,@RAIDManager)";
}
else
{
Label2.Text = "Error";
}
try
{
connection.Open();
SqlCommand cmd = new SqlCommand(sqlStatement, connection);
cmd.Parameters.AddWithValue("@ID", ID);
cmd.Parameters.AddWithValue("@RackName", Name);
cmd.Parameters.AddWithValue("@qty", qty);
cmd.Parameters.AddWithValue("@type", type);
cmd.Parameters.AddWithValue("@desc", desc);
cmd.Parameters.AddWithValue("@model", model);
cmd.Parameters.AddWithValue("@sn", sn);
cmd.Parameters.AddWithValue("@AssetTag", tag);
cmd.Parameters.AddWithValue("@city", cty);
cmd.Parameters.AddWithValue("@NodeName", node);
cmd.Parameters.AddWithValue("@IPAddress", ip);
cmd.Parameters.AddWithValue("@FloatIP", fip);
cmd.Parameters.AddWithValue("@Processors", pro);
cmd.Parameters.AddWithValue("@ram", ram);
cmd.Parameters.AddWithValue("@HardDisks", hd);
cmd.Parameters.AddWithValue("@RAIDManager", rmana);

cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert/Update Error:";
msg += ex.Message;
throw new Exception(msg);

}
finally
{
connection.Close();
}
}

protected void Button2_Click(object sender, EventArgs e)
{
AddNewRecord(TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text,TextBox11.Text,TextBox11.Text,TextBox12.Text,TextBox13.Text,TextBox14.Text,TextBox15.Text,TextBox16.Text,TextBox17.Text, false);
//Re Bind GridView to reflect changes made
binddata();
}
Posted

1 solution

why dont apply order by clause on ur select statement at time of bind data to gridview
exa.
"select * from tablename by id asc"
 
Share this answer
 
Comments
fak_farrukh 24-Apr-13 6:15am    
what query i have to write
Pallavi Waikar 24-Apr-13 6:53am    
i want to say ur id are like 1,2,3,...then ur last added id is 4 and u want to display it at end of grid then when u bind ur gridview at that time in select statement use order by clause.

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