-1

次のコードがあります。

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();

行、それ以上のコマンドは実行されていません。

4

3 に答える 3

2

あなたは構文について確信がありますか?

SqlCommand komut = new SqlCommand("AgentBilgisiDondur')", SqlBaglanti);

AgentBilgisiDondur ではなく AgentBilgisiDondur というストアド プロシージャがあると思います')

SqlCommand komut = new SqlCommand("AgentBilgisiDondur", SqlBaglanti);

アドバイス: のように列が英語であるため、英語を使用するようにしてくださいUserName。だからあなたは試すことができReturnAgentInformationます;)

于 2012-08-18T11:44:53.103 に答える
0

sqlconnection 自体ではなく、sql コマンドを使用してデータベース接続を開く必要があります。コマンドに t を正しく渡しました。ここで、コマンドはそれを開く必要があります。

add this 行SqlBaglanti.Open();を呼び出す前に削除します。ExecuteReader()

SqlCommand.Connection.Open();

于 2012-08-18T11:36:22.240 に答える
0

間違いは、パラメーターが正しくないことです (ストアド プロシージャの passowrd エージェントなどのいくつかのパラメーターを見逃しているか、ストアド プロシージャの名前が間違っています) チェックしてください

于 2012-08-18T11:42:00.503 に答える