Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. sql database problem

sql database problem

Scheduled Pinned Locked Moved C#
databasequestionsysadminsecurityhelp
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    angels777
    wrote on last edited by
    #1

    hi .i have problem connecting the database to the textbox SqlConnection cnn = new SqlConnection("server=(local); database=pubs;Integrated Security=SSPI"); SqlDataAdapter da = new SqlDataAdapter("select * from authors", cnn); DataSet ds = new DataSet(); da.Fill(ds); if i settle the connection above.. how do i connect the data from table authors e.g. 'name' to the textbox.. this.textbox.text = ???????

    J 1 Reply Last reply
    0
    • A angels777

      hi .i have problem connecting the database to the textbox SqlConnection cnn = new SqlConnection("server=(local); database=pubs;Integrated Security=SSPI"); SqlDataAdapter da = new SqlDataAdapter("select * from authors", cnn); DataSet ds = new DataSet(); da.Fill(ds); if i settle the connection above.. how do i connect the data from table authors e.g. 'name' to the textbox.. this.textbox.text = ???????

      J Offline
      J Offline
      Jacky Yiu
      wrote on last edited by
      #2

      this.textbox.text = ds.DataTable[0].Rows[0]["name"].ToString();

      A 1 Reply Last reply
      0
      • J Jacky Yiu

        this.textbox.text = ds.DataTable[0].Rows[0]["name"].ToString();

        A Offline
        A Offline
        angels777
        wrote on last edited by
        #3

        why datatable is there??

        A 1 Reply Last reply
        0
        • A angels777

          why datatable is there??

          A Offline
          A Offline
          angels777
          wrote on last edited by
          #4

          datatable's function is to get one record .. DataTable table999; string command = "select * from Table1"; SqlDataAdapter father = new SqlDataAdapter(command, myConnection); DataSet son = new DataSet(); father.Fill(son,"Table1"); table999 = son.Tables["Table1"]; this.aaa.Text= table999.Rows[0]["name"].ToString(); it said tat the father.fill(son,"Table1") got problem

          J 1 Reply Last reply
          0
          • A angels777

            datatable's function is to get one record .. DataTable table999; string command = "select * from Table1"; SqlDataAdapter father = new SqlDataAdapter(command, myConnection); DataSet son = new DataSet(); father.Fill(son,"Table1"); table999 = son.Tables["Table1"]; this.aaa.Text= table999.Rows[0]["name"].ToString(); it said tat the father.fill(son,"Table1") got problem

            J Offline
            J Offline
            Jacky Yiu
            wrote on last edited by
            #5

            Because the table name is the one you added in the dataset: DataTable table999; string command = "select * from Table1"; SqlDataAdapter father = new SqlDataAdapter(command, myConnection); DataSet son = new DataSet(); son.Tables.Add("Table1"); father.Fill(son, "Table1"); ... That's work. But there has only one select statement in your case, why don't you use the index rather than table name?

            A 1 Reply Last reply
            0
            • J Jacky Yiu

              Because the table name is the one you added in the dataset: DataTable table999; string command = "select * from Table1"; SqlDataAdapter father = new SqlDataAdapter(command, myConnection); DataSet son = new DataSet(); son.Tables.Add("Table1"); father.Fill(son, "Table1"); ... That's work. But there has only one select statement in your case, why don't you use the index rather than table name?

              A Offline
              A Offline
              angels777
              wrote on last edited by
              #6

              how to do that in index? can u pls kindly show your code. thanks

              J 1 Reply Last reply
              0
              • A angels777

                how to do that in index? can u pls kindly show your code. thanks

                J Offline
                J Offline
                Jacky Yiu
                wrote on last edited by
                #7

                As I posted before: this.textbox.text = ds.DataTable[0].Rows[0]["name"].ToString();

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups