刚刚掌握了c#的基础知识,所以如果这是一个简单的修复/没有正确解释,我提前道歉
故事目标:制作一个连接来自 sql 的信息的 UI
问题:错误如标题所述,尽我所知尝试修复它,绕过它等。
当用户选择“查看狗窝”时,我想要做的是在 UI 面板中显示狗窝的结果
理论上它应该是这样的:
狗窝名称 [txtbox "example"]
Address1 [txtbox "Example"]
等等...
private void **Kennel_Load(object sender, EventArgs e)** <-------Error
{
DataTable dt = _kennelDAL.GetKennel(_kennelDAL);
if (dt.Rows.Count > 0)
{
DataRow row = dt.Rows[0];
txtKennelName.Text = row["Name"].ToString();
txtAddress1.Text = row["Address1"].ToString();
txtAddress2.Text = row["Address2"].ToString();
txtAddress3.Text = row["Address3"].ToString();
txtPostcode.Text = row["Postcode"].ToString();
txtCapacity.Text = row["Capacity"].ToString();
}
}
此代码定义来自...
public DataTable GetKennel(string name, string address1, string address2, string address3,string postcode, int capacity)
{
DataTable dt = new DataTable();
//Code here
using (SqlConnection con = new SqlConnection(ConnectionString))
{
SqlCommand cmd = new SqlCommand("[dbo].[Kennel_SelectByID]", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Kennel_Name", name);
cmd.Parameters.AddWithValue("@Kennel_Address1", address1);
cmd.Parameters.AddWithValue("@Kennel_Address2", address2);
cmd.Parameters.AddWithValue("@Kennel_Address3", address3);
cmd.Parameters.AddWithValue("@Kennel_postcode", postcode);
cmd.Parameters.AddWithValue("@Kennel_capacity", capacity);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
}
return dt;
如果这个问题有问题,再次道歉,只是在这个问题上停留了很长一段时间!干杯