我有以下代码:
OpeningForm of = new OpeningForm();
of.ShowDialog();
SqlConnection SqlBaglanti = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MolaTakip; integrated security=true");
SqlBaglanti.Open();
SqlCommand komut = new SqlCommand("AgentBilgisiDondur')", SqlBaglanti);
komut.CommandType = System.Data.CommandType.StoredProcedure;
komut.Parameters.AddWithValue("@LoginName", ThisAgent.LoginName);
SqlDataReader dr = komut.ExecuteReader();
while (dr.Read())
{
ThisAgent.AgentID = int.Parse(dr["UserID"].ToString());
ThisAgent.AgentAdi = dr["UserName"].ToString();
}
SqlBaglanti.Close();
FileStream fs = new FileStream(@"C:\agent.bin", FileMode.OpenOrCreate);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, ThisAgent);
所有这些代码都写在Form_Load
事件中。但是表单加载在
SqlDataReader dr = komut.ExecuteReader();
行,其他命令未运行。