日期:2014-05-18  浏览次数:20765 次

调用mysql存储过程
public DataTable selectAllPerson() 

string constr = "UserId=root;Host=localhost;Database=test;password=1234"; 
MySqlConnection conn = new MySqlConnection(constr); 
MySqlDataAdapter sda=new MySqlDataAdapter(); 
sda.SelectCommand =new MySqlCommand("sp_Select(存储过程名称)",conn); 
DataSet ds = new DataSet(); 
sda.Fill(ds,"T_User"); 
return ds.Tables["T_User"]; 




public DataTable selectAllPerson() 

string constr = "UserId=root;Host=localhost;Database=test;password=1234"; 
MySqlConnection conn = new MySqlConnection(constr); 
MySqlDataAdapter sda=new MySqlDataAdapter(); 
sda.SelectCommand =new MySqlCommand("select * fromT_User",conn); 
DataSet ds = new DataSet(); 
sda.Fill(ds,"T_User"); 
return ds.Tables["T_User"]; 


为什么上面这个程序执行会出错?

------解决方案--------------------
sda.SelectCommand.CommandType = CommandType.StoredProcedure