当前位置:编程学习 > C#/ASP.NET >>

asp.net的数据库连接问题

MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("192.168.0.56", "antshop", "root", "qwe123").AsString);
            conn.Open();
string sql = "SELECT a.salesman,SUM(b.qty/b.qtyOfPackage),b.expiryDate FROM saleorderbill a,saleorderbilldetail b,brand c,goods d WHERE a.billCode=b.billCode AND b.goods_id=d.id AND d.brand_id=c.id AND b.money<>0 AND a.salesman='刘俊斌' GROUP BY a.salesman,c.`name`,b.expiryDate";
            MySQLCommand comm = new MySQLCommand(sql, conn);
            comm.ExecuteNonQuery();
            MySQLDataAdapter da = new MySQLDataAdapter();
            da.SelectCommand = comm;
            DataSet ds = new DataSet();
            da.Fill(ds);

为什么运行的时候ds中没有想要的数据,哪里出了问题? 数据库 asp.net --------------------编程问答-------------------- ds.Fill(da);

把执行的数据放到ds中 --------------------编程问答-------------------- 楼上的不行的话,你就在数据库中运行看你的SQL语句看看是否能查出数据来。 --------------------编程问答--------------------  comm.ExecuteNonQuery();//这句去掉 --------------------编程问答--------------------
引用 3 楼 guwei4037 的回复:
 comm.ExecuteNonQuery();//这句去掉

同上 --------------------编程问答--------------------

MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("192.168.0.56", "antshop", "root", "qwe123").AsString);
            conn.Open();
string sql = "SELECT a.salesman,SUM(b.qty/b.qtyOfPackage),b.expiryDate FROM saleorderbill a,saleorderbilldetail b,brand c,goods d WHERE a.billCode=b.billCode AND b.goods_id=d.id AND d.brand_id=c.id AND b.money<>0 AND a.salesman='刘俊斌' GROUP BY a.salesman,c.`name`,b.expiryDate";
            MySQLDataAdapter da = new MySQLDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
--------------------编程问答-------------------- 楼主的C#代码虽然写的不咋地,但好像可以实现功能,下面是我用SqlServer仿照楼主写的一段数据库代码,在SqlDataAdapter的Fill()方法之前同样也执行了一次ExecuteNonQuery(),数据是可以查询到的。
所以我觉得楼主的问题可能出在sql语句上,另外如果断点设在了Fill()方法处,程序是在Fill()方法执行之前停下来的,此时DataSet对象中还没有被填充数据呢

SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthWind"].ToString());
conn.Open();
string sql = "select * from Employees";
SqlCommand comm = new SqlCommand(sql, conn);
comm.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataSet ds = new DataSet();
da.Fill(ds, "emp");

grid1.DataSource = ds.Tables["emp"];
grid1.DataBind();
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,