I want a insert query for a temp table

Posted by John Stephen on Stack Overflow See other posts from Stack Overflow or by John Stephen
Published on 2010-05-26T10:27:50Z Indexed on 2010/05/26 10:31 UTC
Read the original article Hit count: 244

Filed under:
|
|

Hi..I am using C#.Net and Sql Server ( Windows Application ). I had created a temporary table. When a button is clicked, temporary table (#tmp_emp_answer) is created. I am having another button called "insert Values" and also 5 textboxes. The values that are entered in the textbox are used and whenever com.ExecuteNonQuery(); line comes, it throws an error message Invalid object name '#tbl_emp_answer'.. Below is the set of code.. Please give me a solution.

Code for insert (in insert value button):

private void btninsertvalues_Click(object sender, EventArgs e)  
{
    username = txtusername.Text;
    examloginid = txtexamloginid.Text;
    question = txtquestion.Text;
    answer = txtanswer.Text;
    useranswer = txtanswer.Text;
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=tempdb;Integrated Security=True;");
    SqlCommand com = new SqlCommand("Insert into #tbl_emp_answer values('"+username+"','"+examloginid+"','"+question+"','"+answer+"','"+useranswer+"')", con);
    con.Open();
    com.ExecuteNonQuery();
    con.Close();
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET