Hai,
I'm using these codings to pass values to insert query during runtime i.e; from TextBox control. Given here is partial coding, anyone pls give me a sample coding just to insert atleast 2 values to db Table from the user.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace Student {
class InsertDemo: System.Windows.Forms.Form {//start of classprivate System.Data.OleDb.OleDbConnection myCon;
private void InitializeComponent(){
this.myCon = new System.Data.OleDb.OleDbConnection();
this.myCon.ConnectionString = @"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Saami;Data Source=sqltech-20;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FAC-1;Use Encryption for Data=False;Tag with column collation when possible=False";
...
}
private void button1_Click(object sender, System.EventArgs e)
{
OleDbCommand ins=new OleDbCommand("insert into Student(regno, studName, mark1, mark2, mark3, mark4) "+
"values (@regno, @studName, @mark1, @mark2, @mark3, @mark4", myCon);
ins.Parameters.Add("@regno", OleDbType.VarChar,10);
ins.Parameters["@regno"].Value=textBox1.Text;
ins.Parameters.Add("@studName", OleDbType.VarChar,15);
ins.Parameters["@studName"].Value=textBox2.Text;
ins.Parameters.Add("@mark1", OleDbType.Integer);
ins.Parameters["@mark1"].Value=Int32.Parse(textBox3.Text);
ins.Parameters.Add("@mark2", OleDbType.Integer);
ins.Parameters["@mark2"].Value=Int32.Parse(textBox4.Text);
ins.Parameters.Add("@mark3", OleDbType.Integer);
ins.Parameters["@mark3"].Value=Int32.Parse(textBox5.Text);
ins.Parameters.Add("@mark4", OleDbType.Integer);
ins.Parameters["@mark4"].Value=Int32.Parse(textBox6.Text);
int res=0;
try
{
ins.Connection.Open();
res=ins.ExecuteNonQuery();
ins.Connection.Close();
textBox1.Text=res.ToString()+" records inserted";
}
catch{}
}
}//class
}//namespace
THANKS....

passing runtime queries to DB...
Andy Ho