using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; namespace WindowsApplication8 { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; DataSet daset; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(232, 40); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 0; this.textBox1.Text = ""; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // textBox2 // this.textBox2.Location = new System.Drawing.Point(232, 96); this.textBox2.Name = "textBox2"; this.textBox2.TabIndex = 1; this.textBox2.Text = ""; // // button1 // this.button1.Location = new System.Drawing.Point(256, 192); this.button1.Name = "button1"; this.button1.TabIndex = 2; this.button1.Text = "insert"; this.button1.Click += new System.EventHandler(this.button1_Click); // // label1 // this.label1.Location = new System.Drawing.Point(48, 40); this.label1.Name = "label1"; this.label1.TabIndex = 3; // // label2 // this.label2.Location = new System.Drawing.Point(48, 104); this.label2.Name = "label2"; this.label2.TabIndex = 4; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(528, 266); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { OleDbConnection con=new OleDbConnection("user id=sa; password= ; initial catalog=northwind ; data source=ayman;Connect Timeout=30; Provider=SQLOLEDB" ); con.Open(); OleDbCommand com=new OleDbCommand(); OleDbDataAdapter adbtor=new OleDbDataAdapter(); daset=new DataSet(); //"+Int32.Parse(TextBox3.ToString())+","+Int32.Parse(TextBox4.ToString()) +",'"+TextBox1.ToString() +"','"+ TextBox2.ToString()+"' //stsql="insert into reserved (Emp_id,R_id,ST_date,End_date) values (2,3,22/7/2003,22/8/2003)"; string stsql="select * from city "; com.Connection=con; //com.CommandType=CommandType.Text; //com.CommandTimeout=30; com.CommandText=stsql; adbtor.SelectCommand=com; adbtor.Fill(daset,"tab1"); //ad.Update(da); DataTable t2=this.daset.Tables["tab1"]; DataRow drow=t2.NewRow (); drow["idcity"]=this.textBox1.Text.ToString(); if(this.textBox2.Text !="") drow["idname"]=this.textBox2.Text.ToString(); //if(this.TextBox3.Text!="") //drow["R_Location"]=this.TextBox3.Text.ToString(); //if(this.TextBox4.Text!="") //drow["R_price"]=this.TextBox4.Text.ToString(); //if(this.TextBox5.Text!="") //drow["R_name"]=this.TextBox5.Text.ToString(); //if(this.TextBox6.Text!="") //drow["R_desc"]=this.TextBox6.Text.ToString(); //if(this.TextBox7.Text!="") //drow["R_valed"]=this.TextBox7.Text.ToString(); t2.Rows.Add(drow); OleDbCommandBuilder cmd = new OleDbCommandBuilder(adbtor); adbtor.InsertCommand = cmd.GetInsertCommand(); adbtor.Update(daset,"tab1"); textBox1.Clear(); textBox2.Text=""; } private void textBox1_TextChanged(object sender, System.EventArgs e) { } } }