本文介绍了在C#中创建临时表,我试图在其中复制tabl,一个sqlexception(无效对象名'#xyz'。)是创建临时表的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=.;AttachDbFilename=C:\Users\Amit\Documents\ghf.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

            SqlDataAdapter sda = new SqlDataAdapter(("create table  #xyz(pid int, pname nvarchar(50),pamount nvarchar(50),cid int,cname nvarchar(50)"), con);
            dt = new DataTable();
            sda.Fill(dt);   

           dataGridView1.DataSource = dt;
        }


SqlConnection con = new SqlConnection(@"Data Source=.;AttachDbFilename=C:\Users\Amit\Documents\ghf.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
            SqlCommand cmd = new SqlCommand("insert into #xyz (pid, pname, pcost , cid ,cname) select  product.pid,product.pname,product.pcost ,category.cid ,category.cname  from product inner join category on product.cid = category.cid", con);
             
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.DataSource = dt;

推荐答案




这篇关于在C#中创建临时表,我试图在其中复制tabl,一个sqlexception(无效对象名'#xyz'。)是创建临时表的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 04:06