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. Web Development
  3. ASP.NET
  4. to call the value from the database

to call the value from the database

Scheduled Pinned Locked Moved ASP.NET
database
6 Posts 3 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.
  • V Offline
    V Offline
    varsh12
    wrote on last edited by
    #1

    I have a table which name is login & contain 3 columns. Such as: Name,password & code. In code column contains the table name. eg: table1,table2 so on. And I also create the table of same name as mentioned in code column which is mentioned above. My requirement is that I insert the value in table1 or table2. but in insert query I want to put the table name from the code column. I use following two methods but it didn’t work::

    string code = " select code from login where user_name= name";
    da = new SqlDataAdapter(code, con);
    string s = da.Fill(ds, "c");
    string time = " insert into '"+s+"' values (getdate(),getdate())";
    da = new SqlDataAdapter(time, con);
    da.Fill(ds, "b");
    ------------OR-------------
    string code = " select code from login where user_name = name'";
    string time = " insert into '"+code+"' values (getdate(),getdate())";
    da = new SqlDataAdapter(time, con);
    da.Fill(ds, "b");

    thanks in advance

    N T 2 Replies Last reply
    0
    • V varsh12

      I have a table which name is login & contain 3 columns. Such as: Name,password & code. In code column contains the table name. eg: table1,table2 so on. And I also create the table of same name as mentioned in code column which is mentioned above. My requirement is that I insert the value in table1 or table2. but in insert query I want to put the table name from the code column. I use following two methods but it didn’t work::

      string code = " select code from login where user_name= name";
      da = new SqlDataAdapter(code, con);
      string s = da.Fill(ds, "c");
      string time = " insert into '"+s+"' values (getdate(),getdate())";
      da = new SqlDataAdapter(time, con);
      da.Fill(ds, "b");
      ------------OR-------------
      string code = " select code from login where user_name = name'";
      string time = " insert into '"+code+"' values (getdate(),getdate())";
      da = new SqlDataAdapter(time, con);
      da.Fill(ds, "b");

      thanks in advance

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Your code is broken.

      ahmad25 wrote:

      string s = da.Fill(ds, "c");

      SqlDataAdapter.Fill is not returning string.

      ahmad25 wrote:

      string time = " insert into '"+s+"' values (getdate(),getdate())";

      You are not taking value from the filled dataset. Try this

      string code = "select code from login where user_name= name";
      string s;
      using(SqlCommand command = new SqlCommand(code,con)){
      con.Open();
      s = (string)command.ExecuteScalar();
      con.Close();
      }
      string time = " insert into [" + s +"] values (getdate(),getdate())";

      Navaneeth How to use google | Ask smart questions

      V 1 Reply Last reply
      0
      • V varsh12

        I have a table which name is login & contain 3 columns. Such as: Name,password & code. In code column contains the table name. eg: table1,table2 so on. And I also create the table of same name as mentioned in code column which is mentioned above. My requirement is that I insert the value in table1 or table2. but in insert query I want to put the table name from the code column. I use following two methods but it didn’t work::

        string code = " select code from login where user_name= name";
        da = new SqlDataAdapter(code, con);
        string s = da.Fill(ds, "c");
        string time = " insert into '"+s+"' values (getdate(),getdate())";
        da = new SqlDataAdapter(time, con);
        da.Fill(ds, "b");
        ------------OR-------------
        string code = " select code from login where user_name = name'";
        string time = " insert into '"+code+"' values (getdate(),getdate())";
        da = new SqlDataAdapter(time, con);
        da.Fill(ds, "b");

        thanks in advance

        T Offline
        T Offline
        Tarun Dudhatra
        wrote on last edited by
        #3

        Hi, If in login table you told that value is like table1,table2 etc. After retriving data from that column you directly inserted in insert query I don't think so you can insert data more that one table at a time. As per your code you are trying to write this query insert into table1,table2 values ('1','1'); It will generate error. Am I right? Other wise after retriving that data split it with , then loop and fire insert query. Just reply am I write with above query. And also describe the error message perfactly. http://techiefromsurat.blogspot.com

        V 1 Reply Last reply
        0
        • N N a v a n e e t h

          Your code is broken.

          ahmad25 wrote:

          string s = da.Fill(ds, "c");

          SqlDataAdapter.Fill is not returning string.

          ahmad25 wrote:

          string time = " insert into '"+s+"' values (getdate(),getdate())";

          You are not taking value from the filled dataset. Try this

          string code = "select code from login where user_name= name";
          string s;
          using(SqlCommand command = new SqlCommand(code,con)){
          con.Open();
          s = (string)command.ExecuteScalar();
          con.Close();
          }
          string time = " insert into [" + s +"] values (getdate(),getdate())";

          Navaneeth How to use google | Ask smart questions

          V Offline
          V Offline
          varsh12
          wrote on last edited by
          #4

          hii! Thanks a lot to Mr. Navneeth. you r really solved my problem. I have one more problem. In above program I fetch only one value from a column. if I want to fetch a entire row what can I do? thanks again

          N 1 Reply Last reply
          0
          • T Tarun Dudhatra

            Hi, If in login table you told that value is like table1,table2 etc. After retriving data from that column you directly inserted in insert query I don't think so you can insert data more that one table at a time. As per your code you are trying to write this query insert into table1,table2 values ('1','1'); It will generate error. Am I right? Other wise after retriving that data split it with , then loop and fire insert query. Just reply am I write with above query. And also describe the error message perfactly. http://techiefromsurat.blogspot.com

            V Offline
            V Offline
            varsh12
            wrote on last edited by
            #5

            Hi! Thanks for your reply. but i think you do not understand my question. it is right that we can't insert data at a time more than one table. Mr. Navneeth give me a right query. Thanx

            1 Reply Last reply
            0
            • V varsh12

              hii! Thanks a lot to Mr. Navneeth. you r really solved my problem. I have one more problem. In above program I fetch only one value from a column. if I want to fetch a entire row what can I do? thanks again

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              ahmad25 wrote:

              I fetch only one value from a column. if I want to fetch a entire row what can I do?

              ExecuteScalar can return only a single column. Use ExecuteReader instead. Take it to a SqlDataReader instance.

              Navaneeth How to use google | Ask smart questions

              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