Saturday, 19 October 2013

how to connect front end and back end in c#.net


1. First of all you need to download sql server r2 it consist of 5.28 gb nearly download at following link
http://kickass.to/microsoft-sql-server-2008-r2-x86-x64-t6685091.html
2. Second you need microsoft visual studio download the software following link
http://kickass.to/usearch/microsoft%20visual%20studio/

step: 1 open the sql server r2


step : 2 click connect and you may see this screen


step : 3 To create the data base


step : 4 Type Your Data Base Name


step : 5 Click the OK button


step : 6 Now your data base is created


step 7: Now you create table


step 8: Now type the column name and choose data type and then tick the allow not null chechbox and save by using ctrl+s and then enter the table name here i am using table name (logintable)
                                                                            1

2


step 9 now your table created.....


Step 10 : open new project in visual studio


Step 11 : Design a Form like this


Step 12 : Double click the save button



Step 13 : Add the namespace


Step 14 : Now you get the connection string following the methods in the visual studio ( ctrl+w+s) to open the solution explorer

Step 15 : Add a connection


Step 16 : Select Sql server connection

Step 17 : Select or Enter your server name( manually)
1.ENTER THE SERVER NAME
2 HERE YOUR SERVER NAME
3 TYPE YOUR SERVER NAME
4 SELECT YOUR DATA BASE NAME AND CLICK OK

Step : 18 Now your ready to connect the front end and back end...


Step : 19 Now you copy the connection string and past it to the coding 

Step : 20 Add the namespace

using System.Data;
using System.Data.SqlClient;

1. past your connection string in the coding.. see the screen shot u will understand
your coding : try this

 private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=VIGNESH-PC;Initial Catalog=sampledatabase;Integrated Security=True");
            con.Open();
            SqlCommand cmd=new SqlCommand("insert into logintable values('"+textBox1.Text+"','"+textBox2.Text+"')",con);
            int r=cmd.ExecuteNonQuery();
            if (r > 0)
            {
                MessageBox.Show("inserted successfully");
            }
            con.Close();
        }

Step : 21 Execute your code press F5.


Step : 22 Check the database

Step : 23 Final Result


No comments:

Post a Comment