Loading ...

SQL

Who is online?  0 guests and 1 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » SQL

SQL

Posts under the topic: SQL

Posted: 12/14/2011

Lurker 5  points  Lurker
  • Joined on: 12/14/2011
  • Posts: 1

I have got 5 textboxes, button and customers table within my database.

I want when customers inplement the data that going into database automatic.

 

can someone help to do that


tags Sql

Posted: 12/15/2011

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424

Can you please be more specific? Are you trying to insert the data that is coming from the textbox to the database? If so then you can do something like this using the ADO.NET way:

public string GetConnectionString()
{
    return System.Configuration.ConfigurationManager.ConnectionStrings["ConnStringName"].ConnectionString; 
   //sets the connection string from your web config file "ConnString" is the name of your Connection String

}


private void InsertInfo()
{

       SqlConnection conn = new SqlConnection(GetConnectionString());
       string sql = "INSERT INTO connect_com (name,E_mail,School ) VALUES (@Val1,@Val2,@Val3)";
       try
       {
           conn.Open();
           SqlCommand cmd = new SqlCommand(sql, conn);
           cmd.Parameters.AddWithValue("@Val1", txtName.Text);
           cmd.Parameters.AddWithValue("@Val2", txtEmail.Text);
           cmd.Parameters.AddWithValue("@Val3", txtSchool.Text);
           cmd.CommandType = CommandType.Text;
           cmd.ExecuteNonQuery();
       }
       catch (System.Data.SqlClient.SqlException ex)
       {
                string msg = "Insert Error:";
                msg += ex.Message;
                throw new Exception(msg);

       }
       finally
       {
       conn.Close();
       }
}

protected void Button1_Click(object sender, EventArgs e)
{
       InsertInfo();
}

You can also refer to the link below for another example:

Creating a Simple Registration Form in ASP.NET


Page 1 of 1 (2 items)