Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
protected void Button3_Click1(object sender, EventArgs e)
    {
        con.ConnectionString = "Data Source=BHUSHAN-PC\\SQLEXPRESS;Initial Catalog=Learn;Integrated Security=True";
        con.Open();

string s1="";
      string s2 = "";
      string s3 = Session["FirstName"].ToString();
      string s4 = ""
      string s5 = ""
      string s6 = "";
      string s7 = Ques.Text;
      string s8 = "";

      cmd.Connection = con;
      cmd.CommandText = "insert into QAtbl values('" + s1 + "'," + "'" + s2 + "'," + "'" + s3 + "'," + "'" + s4 + "'," + "'" + s5 + "'," + "'" + s6 + "'," + "'" + s7 + "'," + "'" + s8 + "')";
      cmd.ExecuteNonQuery();
            }
}

In the above code I have different values.
I want to insert the values from other table to some undefined string like s1,s4,s5 and then execute the insert statement. What should I do? plz...suggest me!!!
Thanks in advance
Posted
Updated 23-Jan-14 23:44pm
v3
Comments
Karthik_Mahalingam 24-Jan-14 5:38am    
Not clear..
pls provide more info...
Krunal Rohit 24-Jan-14 5:40am    
Session is not working ?
samit kaneriya 24-Jan-14 5:50am    
give brief detail of table field which u want to insert and variable detail which u want to pass
Ahmed Bensaid 24-Jan-14 6:38am    
You have to create and execute another sql query (SELECT) before your INSERT query.
And fill your variables with the returned results of your first query (SELECT).
Then, you can make your INSERT query ;)
bhushan sinkar 28-Jan-14 4:08am    
am unable to assign selected result to respected string!!

You need not to convert it into string at all time while formulating ado.net query..

You can do same thing by using entity object..
It's not good to execute query on button event itself.

If you assign data table column value to string then can do something like this.
C#
string s2=Convert.ToString(dataTable.Rows[0]["column name"]);
 
Share this answer
 
Comments
bhushan sinkar 24-Jan-14 7:03am    
Yes sir
but i want to get value to some column from diff table .....
If I am getting you correct then ...
You can use multiple tables according to your choice like
but you should have access to all data tables in that particular function
C#
string s2=Convert.ToString(dataTable1.Rows[0]["column name"]);
string s3=Convert.ToString(dataTable2.Rows[0]["column name"]);
 
Share this answer
 
Comments
bhushan sinkar 28-Jan-14 4:07am    
frds would you help me how to use inner join query..i want to execute both sql statements
V5709 28-Jan-14 4:11am    
Which Statements?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900