c#将查询到SQL的数据放到DataTable里,再根据条件查询放到新的表里

这段C#代码演示了如何从SQL数据库查询数据并将其加载到DataTable中,然后根据特定条件(codeType='01')筛选数据,并将符合条件的记录复制到新的DataTable对象中。
摘要由CSDN通过智能技术生成
 //获取问题类型
        public void getQuestion_type()
        {
            SqlConnection conntype = new SqlConnection(ClassConnAll.conmmsy); //实例化SQLconnection类。连接数据库                                                            
            DataSet Dstype = new DataSet();
            //string Sqltype = "select (ltrim(rtrim(staffid))+'['+ ltrim(rtrim(StaffName))+']') as item_clsno from Hion_AgentInfo";
            string Sqltype = "select *  from codeAll";
            SqlDataAdapter Datype = new SqlDataAdapter(Sqltype, conntype);
            Datype.Fill(Dstype); // Da.Fill(Ds, "t_bd_branch_info");
            DataTable dtAllCode = new DataTable();
            dtAllCode = Dstype.Tables[0];
            conntype.Close();


//dtAllCode的数据,根据字段codeType='01'时,读取数据出来,方且放到新的c 里


            dtAllCode.DefaultView.RowFilter = "codeType='01'";
            DataTable c = dtAllCode.DefaultView.ToTable();            
        } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值