"Help needed" visual web developer 2008(asp.net c#)

sanoob.tv

Dr.gB
i hav been working on asp.net(c#) for past few days.
i created a table named "sum" having coloumns(registerno,name)under database "trial".

in my aspx web page,i have provided 2 text boxes(Textbox1 for registerno & textbox2 for name)and a button.

what im looking for is a way to insert the contents of the textboxes to the table"sum";i have the button click event,the contents of the text box,and the sql command to insert;

can any one tell me the code for the same,
thnx in advance
 
if u really tried u can find that code anywhere on the net

u r a beginner, so, just this one time i will give the code ::

Code:
         private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\trial.mdf;Integrated Security=True;User Instance=True"); //change the connection string accordingly
            SqlCommand sqlCmd = new SqlCommand(string.Format("INSERT INTO [sum] VALUES ({0}, '{1}')", TextBox1.Text, TextBox2.Text), sqlConnection);//first is int type and second varchar type
            try{
                 sqlConnection.Open();
                 int rowsAffected = sqlCmd.ExecuteNonQuery();
                 sqlConnection.Close();
                 Label1.Text = rowsAffected.ToString() + " record(s) inserted sucessfully";
            }
            catch(Exception ex)
            {
                  Label1.Text = "Error: " + ex.Message;
             }
             finally{
             sqlConnection.Close();
             }
          }

include namespace
Code:
using System.Data.SqlClient;

and put a label with id Label1

i suppose the code is fairly easy to understand. if in doubt break up the code and try to find it on the net

i recommend a great site. used it in my early days :: *csharp.net-informations.com/
 
Last edited:

manujohn

Journeyman
Coded it self, and yes it was a home work problem.
@arpanmukherjee1 : Your code is little confusing to me since i'm a beginner.
Anyway thanks...
 
Top Bottom