to call the value from the database
-
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
-
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
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
-
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
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
-
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
-
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
-
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
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. UseExecuteReader
instead. Take it to aSqlDataReader
instance.Navaneeth How to use google | Ask smart questions