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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Problem with bind data in textbox

Problem with bind data in textbox

Scheduled Pinned Locked Moved Database
comdata-structureshelp
4 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
    Ahmed R El Bohoty
    wrote on last edited by
    #1

    hi, i note that when i retrieve data and bind it to textbox that when i want to bind to each textbox i do the same thing , so i think to make method where i pass array of the name of textbox and it will bind automatic for each textbox and here is what i try to do

    //Step 1 :
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "student_SelectAll";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Connection = cn;
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = cmd;

            //Step 2 :
            TextBox \[\] txtb={textBox1,textBox2,textBox3,textBox4,textBox5,textBox6,textBox7,textBox8};
    
            //Step 3:
            IDataParameter\[\] param = adapter.GetFillParameters();
            for (int i = 0; i <param.length;>            {
                cmd.Parameters.Add(param\[i\].ParameterName,param\[i\].DbType).Value = txtb\[i\].Text;
            }
    

    Discover Other .... http://www.islamHouse.com

    V 1 Reply Last reply
    0
    • A Ahmed R El Bohoty

      hi, i note that when i retrieve data and bind it to textbox that when i want to bind to each textbox i do the same thing , so i think to make method where i pass array of the name of textbox and it will bind automatic for each textbox and here is what i try to do

      //Step 1 :
      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = "student_SelectAll";
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Connection = cn;
      SqlDataAdapter adapter = new SqlDataAdapter();
      adapter.SelectCommand = cmd;

              //Step 2 :
              TextBox \[\] txtb={textBox1,textBox2,textBox3,textBox4,textBox5,textBox6,textBox7,textBox8};
      
              //Step 3:
              IDataParameter\[\] param = adapter.GetFillParameters();
              for (int i = 0; i <param.length;>            {
                  cmd.Parameters.Add(param\[i\].ParameterName,param\[i\].DbType).Value = txtb\[i\].Text;
              }
      

      Discover Other .... http://www.islamHouse.com

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      What is your Problem?

      Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

      A 1 Reply Last reply
      0
      • V Vimalsoft Pty Ltd

        What is your Problem?

        Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

        A Offline
        A Offline
        Ahmed R El Bohoty
        wrote on last edited by
        #3

        It does not work or how i can do something like this ?

        Discover Other .... http://www.islamHouse.com

        V 1 Reply Last reply
        0
        • A Ahmed R El Bohoty

          It does not work or how i can do something like this ?

          Discover Other .... http://www.islamHouse.com

          V Offline
          V Offline
          Vimalsoft Pty Ltd
          wrote on last edited by
          #4

          There ways that you can do that, if i understand you Correctly , you want to Bind the Results from the DB to the indivisual Textbox. You can Create a Class that has a Function to get you Data , or you can create your Function in your Form (thats not professional) and call your Function like this

          public class Class1
          {
          
            
             public DataTable GetData() 
             {
                int Code;
          
                String strCon = "blablablablablablabla";
          
                SqlConnection con = new SqlConnection(strCon);
          
                SqlCommand cmdselect = new SqlCommand();
          
                cmdselect.CommandType = CommandType.StoredProcedure;  
                
                cmdselect.CommandText = "student\_SelectAll";
          
                cmdselect.Connection = con;
          
                DataTable DT = new DataTable();
          
          
                try
                {
                    con.Open();
          
                    DT = cmdselect.ExecuteNonQuery();
          
                }
                 catch(SqlException)
                {
                     throw; 
                }
                 finally
                {
                    con.Close();
                }
          
                return DT;
                 
             } 
          
            }
          

          This is a Class that has a Function Getdata that returns a Datatable and in your Form you access the Function and Bind the Textbox like this

          Class1 obj = new Class1();

                 DataTable DT = new DataTable();
                 
                  DT =  obj.GetData();
          
                  txtname.Text = DT.Columns\[0\];
          
                  txtlastname.Text = DT.Columns\[1\];
                  //and bla bla blabla 
          

          Am Sorry for the untidy code, am just in a Hurry for a meeting. Hope this Helps :)

          Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za

          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