Results 1 to 2 of 2

Thread: Saving data from text boxes to an SQL server database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2012

    Saving data from text boxes to an SQL server database


    I've been working on a piece of code to get a GUI to input data into then save to an SQL server database but as ever I got stuck. I followed a tutorial for it but now I'm stuck with the wrong type of input (gridview). I tried different ways to get it so I could input into textboxes and save, however there were still always problems.

    I've attached the code for the gridview GUI so you could see where I am with that:

    Imports System.Data.SqlClient
    Public Class Main
        Private connstr As New SqlConnection("ConnectionString")
        Private dadapter As New SqlDataAdapter("Select Name, Age, Address, PkID From tblPatients", connstr)
        Private dset As New DataSet
        Private cmdb As New SqlCommandBuilder(dadapter)
        Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            dadapter.Fill(dset, "tblPatients")
            dgrid.DataSource = dset.Tables("tblPatients")
        End Sub
        Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
            dadapter.UpdateCommand = cmdb.GetUpdateCommand
            MsgBox("Record Saved")
        End Sub
    End Class
    Any help as to how to get it into textboxes then save to the database would be greatly appreciated, and if not then could you point me in the right direction?

    Thank you!

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: Saving data from text boxes to an SQL server database

    Follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data. Amongst others, there's an example of saving one record at a time.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width