In previous posts we have seen CONNECTING WITH SQL SERVER USING ADO.NET , Simple C# program with ADO.NET .
In this post we will see a sample windows application with ADO.NET . I am designing the form as shown in the image below.
To have a look at ouput see the image below:
In this post we will see a sample windows application with ADO.NET . I am designing the form as shown in the image below.
create a table in the databse. Here we are using sql server.
CREATE TABLE EMPTABLE(EMPNAME VARCHAR(25),SALARY DECIMAL)
The code in the code behind file is given below:
using System; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; namespace AdoDemo1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SqlConnection con = new SqlConnection("data source=localhost;initial catalog=sameer;Integrated security=true"); SqlCommand cmd; private void btnsubmit_Click(object sender, EventArgs e) { cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText="insert into emptable(empname,salary) values(@empname,@salary)"; cmd.Parameters.AddWithValue("@empname", txtname.Text); cmd.Parameters.AddWithValue("@salary", decimal.Parse(txtsalary.Text)); con.Open(); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("record inserted successfully"); } } }
Support blog with your valuable comments..
No comments:
Post a Comment
Thanks for your comments.
-Sameer