Connecting Windows Forms to Database(Sql Server) with Navigation Buttons-Previous, Next, First, Last

We have shifted.. is now

Find this Tutorial in the given link.


29 thoughts on “Connecting Windows Forms to Database(Sql Server) with Navigation Buttons-Previous, Next, First, Last

  1. Pingback: Back Button Functionality in Windows Forms using C# in .NET | Programming Palace

  2. private static SqlConnection con = new SqlConnection(“Data Source=PCName\\SQLEXPRESS; ” +
    “Initial Catalog=TestDB;Integrated Security=True”);

    This is the Connection String I have used….

    now Data Source should be your Server Name
    My Server Name is something like this PCName\SQLEXPRESS.
    Change it according to your Server which you are using.

    Initial Catalog is Database Name. Here my DB Name is TestDB

    I am using Windows Authentication. So no Username and Password.
    But if you use SQL Server Authentication, then you have to add User Id and Password field to the connection string.

    It may look like this User Id=System; Password=password

    So your Connection String will look something like this-

    private static SqlConnection con = new SqlConnection(“Data Source=PCName\\SQLEXPRESS; ” +
    “Initial Catalog=TestDB;Integrated Security=True;User Id=System; Password=password “);

  3. Good work…pls how do i use a combobox to add data to a database i.Ƹ̵ any item selected from the drop down menu will b added to a column in the database
    Assuming i want to sort this contact details by age i.Ƹ̵ distributing the contact detail table into another table age_group
    How do i code a btnLogin of a login such that a user must enter password and username. Thanks

  4. Update Is Not Working Properly.When I click On Update Button,It Is Always showing “Failed to update Contact”….

    • This code is written using Windows Authentication. Thats why I haven’t used UserId and Password in the connection string.. Try an application creating only the connection.

  5. sir i am getting exceptions like indexoutof range exception where u declared
    contactid.text= ds.tables[0].rows[postion][0].tostring();

      • sir ya i solved this problem yesterday but can u plzz help me out in finding particular row from the table . I mean if i have one texbox more and a search button and if i write a contact id in the textbox on clicking the button the row having that id would be displayed plzz sir help me in this code and thanx for the help

      • For getting one record using Contact ID…I suggest you use SqlDataReader.
        The code is as below. Modify as per your needs

        //Store the ContactId in a Variable
        Int32 iContactID = Convert.ToInt32(textBoxContactID.Text);
        //Open Connection
        SqlCommand cmd = new SqlCommand(“SELECT * FROM contact_details WHERE ContactId = @Id”, conn);

        SqlParameter param = new SqlParameter();
        param.ParameterName = “@Id”;
        param.Value = iContactId;

        SqlDataReader rdr = cmd.ExecuteReader();

        while (rdr.Read())
        textBoxContactId.Text = rdr[“ContactId”].ToString();
        textBoxFirstName.Text = rdr[“FirstName”].ToString();
        textBoxLastName.Text = rdr[“LastName”].ToString();
        textBoxMobileNumber.Text = rdr[“MobileNumber”].ToString();
        textBoxEmailId.Text = rdr[“EmailId”].ToString();
        textBoxDOB.Text = rdr[“DOB”].ToString();

        Hope this helps… 😀

      • thanku so much sir u r a life saviour thanku so much and plzz sugeest me some good ebooks of window application which contain less theory part but more practical part one again thanku sir thanku so much

      • I suggest you clear your ADO .NET Concepts. Find out what is Connected and Disconnected Architecture. For that just google and even msdn is also quite useful. I myself haven’t read many E-Books. Learning through practicals is the best way. And as you work more you will learn that Windows Forms is becoming trivial as WPF and ASP.NET is taking the center stage. I suggest you try out this application
        as it covers How to build an MVC application in Windows Forms. I tried to write it in as simple way as possible. Happy Programming. 😀

      • thanku sir i vl surely try this if i find any difficulty may i ask u about the code?? and anything which i don’t understand

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s