我对编程很陌生,并且在我正在开发的基本应用程序中遇到了问题。我有一个类似于这个的人类......
Person
{
SqlConnection conn = new SqlConnection(@"Integrated Security=True; Data
Source=ME\MyPRESS;Initial Catalog=TEST5");
SqlCommand cmd = new SqlCommand("usp_employee", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@emp_id", SqlDbType.Int).Value = id;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
try
{
conn.Open();
{
department = dr["dept_name"].ToString();
fname = dr["emp_first_name"].ToString();
lname = dr["emp_last_name"].ToString();
email = dr["emp_email"].ToString();
phone = dr["emp_phone"].ToString();
position = dr["emp_position"].ToString();
address1 = dr["emp_address1"].ToString();
address2 = dr["emp_address2"].ToString();
city = dr["emp_city"].ToString();
state = dr["emp_state"].ToString();
postal_code = dr["emp_postal_code"].ToString();
// department = txtFirst_name.Text;
}
}
finally
{
// 3. close the reader
if (dr != null)
{
dr.Close();
}
// close the connection
if (conn != null)
{
conn.Close();
}
}
}
受保护的字符串部门;
public string Department
{
get { return department; }
set { department = value; }
}
protected string fname;
public string Fname
{
get { return fname; }
set { fname = value;}
}
protected string lname;
public string Lname
{
get { return lname; }
set { lname = value; }
}
protected string email;
public string Email
{
get { return email; }
set { email = value; }
}
protected string position;
public string Position
{
get { return position; }
set { position = value; }
}
protected string address1;
public string Address1
{
get { return address1; }
set { address1 = value; }
}
protected string address2;
public string Address2
{
get { return address2; }
set { address2 = value; }
}
protected string phone;
public string Phone
{
get { return phone; }
set { phone = value; }
}
protected string city;
public string City
{
get { return city; }
set { city = value; }
}
protected string state;
public string State
{
get { return state; }
set { state = value; }
}
protected string postal_code;
public string Postal_Code
{
get { return postal_code; }
set { postal_code = value; }
}
}
如上所示,我有一个表单和一个带有存储过程的数据库来检索数据......我迷失的地方是连接我的表单以显示存储过程中的记录。