Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace empdetails
{
public partial class emp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}

protected void TextBox3_TextChanged(object sender, EventArgs e)
{

}

protected int Button1_Click1(object sender, EventArgs e)
{
string str = ConfigurationSettings.AppSettings["rajesh"].ToString();

SqlConnection con=new SqlConnection(str);
con.Open();
string s=("insert into emp values(name=@name,pasword=@pasword,salary=@salary,adress=@adress)");
SqlCommand cmd=new SqlCommand(s,con);
cmd.Parameters.AddWithValue("@name",TextBox1.Text);
cmd.Parameters.AddWithValue("@pasword",TextBox2.Text);
cmd.Parameters.AddWithValue("@salary",TextBox3.Text);
cmd.Parameters.AddWithValue("@adress",TextBox4.Text);

int result=cmd.ExecuteNonQuery();

con.Close();

return result;
}
}
}
Posted
Comments
[no name] 1-Aug-14 7:05am    
Where you stuck in this?

1 solution

What error you are gtetting?
You can refer below code for your refrence -
C#
//Makes a variable that contains your value
string strName= "TestData";

//Inserts the above data variable into the db-table
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "INSERT INTO YourTableName (YourFirstNameColumnName) VALUES (@FirstName)

        //Uses the FirstName variable and creates a new sql variable for use in the sql commandtext
        cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName;

        cmd.Connection = conn;

        conn.Open();

        cmd.ExecuteNonQuery();

        conn.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900