怎么根据查询结果创建临时表并插入数据
依旧先解释下要干什么先,title[]这个数组里存放着一些不重复的正整数,通过这些正整数查询到qid值在这个数组里面的所有数据,得到数据之后我要创建一张临时表以userName命名,然后还要把查询到的结果存到这张临时表里面去,下面是我写的代码,当然是错误百出了,大家知道这个意思就行,然后帮忙改改吧,感激不尽!!!!public static void CreateTable(int[] title,string userName)
{
string sqlWhere = "";
for (int i=0;i<title.Length;i++)
{
sqlWhere+=title[i].ToString()+",";
}
sqlWhere=sqlWhere.Remove(sqlWhere.Length-1);
string strSql="select * from question where qid in ("+sqlWhere+")";
Conn.Open();
Cmd.Connection=Conn;
SqlDataReader dr=Cmd.ExecuteReader();
if (dr.HasRows)
{
string sqlCreate = "create table "+userName+" (id int identity(1,1) primary key NOT NULL,title text not null,A text not null,B text not null,C text not null,D text not null,answer char(2) not null,result tinyint not null)";
Cmd.Connection = Conn;
= sqlCreate;
Cmd.ExecuteNonQuery();
int i = 1;
while (dr.Read())
{
string sqlInsert = "insert into" + userName + "(id,title,A,B,C,D,answer,result) values(" + i + "," + dr["qtitle"].ToString() + "," + dr["qA"].ToString() + "," + dr["qB"].ToString() + "," + dr["qC"].ToString() + ","+ dr["qD"].ToString() + ","+dr["qanswer"]+",0)";
Cmd.Connection = Conn;
= sqlInsert;
Cmd.ExecuteNonQuery();
i++;
}
}
dr.Close();
}