Time remaining:
C# Programming Help Needed

label Economics
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

Could anyone help me to write Asp.net page with database connection in C#?

Apr 3rd, 2015

1: Open visual studio 2005 and from FILE select NEW-> WebSite, then from pop-menu select asp.net website (Note: Language must be C#) , then press OK.

2: Now create three textboxes from the toolbox , to remove ambiguity I am using default name for that textboxes and that should be textbox1,textbox2 & textbox3. And also drag & drop the button to the asp.net application.

3: Meanwhile, Open SQL SERVER Management studio 2005 and open adventureworks(or you can create your own database by the Sql command CREATE DATABASE database_name), but here I am using AdventureWorks database.

4: Then create table by clicking right mouse button and form three column, Name them according to your requirement , for your information only I used EID,name,Address. And click save button, then you'll get a pop up menu where you have to enter the Table Name, for this example I used Employee.

5: Now Come Back to Visual studio Application and write the following code in the button_click event

  1. protectedvoidButton1_Click(object sender,EventArgs e)
  2. {
  3. SqlConnection myConn =newSqlConnection();
  4. myConn.ConnectionString="Connection string(See Below for this -- )COPY PASTE HERE";
  5. myConn.Open();
  6. string strqry ="Insert into students values ("+TextBox1.Text+
  7. ",'"+TextBox2.Text+"','"+TextBox3.Text+"')";
  8. SqlCommand myCom =newSqlCommand(strqry, myConn);
  9. int numrow = myCom.ExecuteNonQuery();
  10. myConn.Close();
  11. }

Kindly note down the connectionString Syntax, to obtain this string do the following steps :
Step 1 : Go to toolbox and from data section drag & drop SqlDataSource.
Step 2: Then on left clicking the mouse on SqlDataSource , you will get configureDataSource link, Slect this.
Step 3: NewConnection String -> Provide Server Name then select or write database name , i.e. AdventureWorks.
Step 4: TestConnection and then Press OK.
Step 5 : Now you will again redirect to the page that you actually see in the step 2, but this time click + sign before the connection string and from the drop drown hierarchy you will receive the connection string.
Step 6: Just copy and paste this string to the place of connectionstring.
Now debug & run Your application and check it's effect on the table.


Apr 3rd, 2015

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Apr 3rd, 2015
...
Apr 3rd, 2015
Jun 29th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer