well i have do make a application that remove, update and add
information in sql tables i have this but i can´t add. can help me
please?
i have this --> http://www.freeimagehosting.net/uploads/e115ce2713.jpg
thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vijaya KadiyalaPosted Feb 26, 2009, 1:16 PM
Hi
You need to use ExecuteNonQuery.
If your command is Insert, Update or Delete, executeNonquery returns an integer specifying the number of rows affected.
Thanks -- Vijaya Kadiyala
Vijaya KadiyalaPosted Feb 27, 2009, 3:46 PM
Hi
i am glad to see that you got the answer. Keep visiting C# Corner to improve your knowledge.
Thanks -- Vijaya Kadiyala
RaulPosted Feb 26, 2009, 2:35 PM
string connectionPath = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Directory.GetCurrentDirectory()+ "\\Teste.mdf" +";Integrated Security=True; Connect Timeout=30;User Instance=True";
SqlConnection sc = new SqlConnection(connectionPath);
sc.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO student VALUES( '" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "')",sc);
int temp = cmd.ExecuteNonQuery();
if (temp > 0)
{
MessageBox.Show("Record Added");
}
else
{
MessageBox.Show("Record not Added");
}
mycon.Close();
lovely nehaPosted Feb 25, 2009, 6:44 AM
hii..
hi ...instead of DataAdapter..use ExcecuteNonQuery...
Cmd.ExecuteNonQuery();
connection.close();