Insert Data into Database using Simple Stored Procedure in SQL

Database Structure

Database Structure


Simple stored procedure for insert.

  1. create procedure insert_userdetail  
  2. (  
  3.    @Username varchar(50),  
  4.    @Password varchar(50),  
  5.    @Address varchar(120),  
  6.    @Mobile varchar(12),  
  7.    @Email varchar(50)  
  8. )  
  9. as  
  10. insert into tbl_ins values(@Username,@Password,@Address,@Mobile,@Email)  
Userdetails.aspx

Userdetail

Userdetails.aspx.cs

Code:
  1. protected void btnins_Click(object sender, EventArgs e)  
  2. {  
  3.    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[“userconnstring”].ConnectionString);  
  4.    SqlCommand cmd = new SqlCommand(“insert_userdetail”, con);  
  5.    cmd.CommandType = CommandType.StoredProcedure;  
  6.    con.Open();  
  7.    cmd.Parameters.AddWithValue(“@Username”, txtusername.Text);  
  8.    cmd.Parameters.AddWithValue(“@Password”, txtpassword.Text);  
  9.    cmd.Parameters.AddWithValue(“@Address”, txtaddress.Text);  
  10.    cmd.Parameters.AddWithValue(“@Mobile”, txtmob.Text);  
  11.    cmd.Parameters.AddWithValue(“@Email”, txtemail.Text);  
  12.    cmd.ExecuteNonQuery();  
  13.    alert.Text = “User Inserted Successfully!”;  
  14.    con.Close();  
  15. }  
Output

Userdetail insert

Screen 1

Database
Screen 2:[Database]
Ebook Download
View all
Learn
View all