我想在C#中使用存儲過程從MySQL數據庫中獲取數據,更確切地說,我遵循以下三層架構代碼我已經嘗試過所有的可能性小的幫助將不勝感激。Asp.net C#Mysql使用存儲過程獲取數據表格數據庫
DataService的層
public DataSet FetchLoginDetails(string SchoolID)
{
object[] objparam = new object[1];
objparam[0] = new MySqlParameter
{
ParameterName = "@SchoolID",
DbType = System.Data.DbType.String,
Value =SchoolID
};
DataSet dsdataRes = ExecuteQuery("Storeprociduer", objparam);
return dsdataRes;
}
BusinessServices
private ITimeTableRepository ObjTimeTable
{
get { return UnityManager.Resolve<ITimeTableRepository>(); }
}
public DataSet FetchLoginDetails(string SchoolID)
{
return ObjTimeTable.FetchLoginDetails(SchoolID);
}
BusnessServices.Interfaces
public interface ITimeTableBO
{
DataSet FetchLoginDetails(string SchoolID);
}
UI的.cs
public void LoadLoginDetails(DataSet ds)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
ddlSubject.Items.Clear();
ListItem item1 = new ListItem();
item1.Text = "Choose a Subject";
item1.Value = "-1";
ddlSubject.Items.Add(item1);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ListItem item = new ListItem();
item.Text = ds.Tables[0].Rows[i]["UserName"].ToString();
item.Value = ds.Tables[0].Rows[i]["UserName"].ToString();
ddlSubject.Items.Add(item);
}
}
.aspx的代碼
<asp:DropDownList ID="ddlSubject" runat="server" Width="150px"
Height="27px" ClientIDMode="Static"
AutoPostBack="true" >
<asp:ListItem Value="-1" Text="Choose a Subject"></asp:ListItem>
</asp:DropDownList>
商店Procidure
CREATE DEFINER=`root`@`localhost` PROCEDURE `Storeprociduer`(
SchoolID
VARCHAR(255)
)
BEGIN
select UserName from scoolage_login where SchoolID =
SchoolID ;
END
您還沒有指定哪個存儲過程調用FetchLoginDetails。 – Drew
@Drew對不起,這是我的錯誤,而在我的代碼發佈我已經提到了商店的程序名稱,但它仍然沒有顯示 – Shaik