ethicalhacker
Well-known member
private void ins_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server=.; database=amit;user id=sa; password=.");
con.Open();
SqlCommand com = new SqlCommand("insert into log1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')", con);
com.ExecuteNonQuery();
con.Close();
}
also if I want to increase the number of columns to be inserted upto textbox7 and use an sql function in the query i get a runtime error saying the string or binary was truncated
for example if I use
SqlCommand com = new SqlCommand("insert into log1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "'," + "getdate()" + ")", con);
So I want 7 fields to have data taken from the 7 textboxes and the 8th field as getdate() which will insert the current date and time in the 8th field.
The above query with 8 fields just doesnt work...
{
SqlConnection con = new SqlConnection("Server=.; database=amit;user id=sa; password=.");
con.Open();
SqlCommand com = new SqlCommand("insert into log1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')", con);
com.ExecuteNonQuery();
con.Close();
}
also if I want to increase the number of columns to be inserted upto textbox7 and use an sql function in the query i get a runtime error saying the string or binary was truncated
for example if I use
SqlCommand com = new SqlCommand("insert into log1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "'," + "getdate()" + ")", con);
So I want 7 fields to have data taken from the 7 textboxes and the 8th field as getdate() which will insert the current date and time in the 8th field.
The above query with 8 fields just doesnt work...