This is a migrated thread and some comments may be shown as answers.

Convert.ToInt32 Insert Command problem

0 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vivek Tyagi
Top achievements
Rank 1
Vivek Tyagi asked on 04 Oct 2011, 03:31 PM

 

protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)

{

 

GridEditFormInsertItem inserteditem = (GridEditFormInsertItem) e.Item;

 

string Name = (inserteditem["Name"].Controls[0] as TextBox).Text;

 

string Last = (inserteditem["Last"].Controls[0] as TextBox).Text;

 

string Address = (inserteditem["Address"].Controls[0] as TextBox).Text;

 

int Age = Convert.ToInt32((inserteditem["Age"].Controls[0] as TextBox).Text);

 

//string Age = (inserteditem["Age"].Controls[0] as TextBox).Text;

 

con.Open();

 

string insertquery = "insert into test values('" + Name + "', '" + Last + "', '" + Address + "', " + Age + ")";

 

SqlCommand sql = new SqlCommand();

sql.CommandText = insertquery;

sql.Connection = con;

sql.ExecuteNonQuery();

 

//Close the SqlConnection

con.Close();

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Vivek Tyagi
Top achievements
Rank 1
Share this question
or