Wednesday, 20 June 2012

insert directly from application to database

string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

try

{

    using (SqlConnection connect = new SqlConnection(connectionString))

    {

        SqlCommand command = new SqlCommand();

        command.Connection = connect;

        command.CommandText = "insert into customer(name, address) values(@name, @address)";

        command.Parameters.Add(new SqlParameter("@name", SqlDbType.VarChar));

        command.Parameters.Add(new SqlParameter("@address", SqlDbType.VarChar));

        command.Parameters["@name"].Value = name.Text.ToLower();

        command.Parameters["@address"].Value = address.Text.ToLower();

        connect.Open();

    }

}

No comments:

Post a Comment