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();
}