私はVisual Studio 2010で作業しておりreport.mdf
、プロジェクトに新しいアイテムをデータベースとして追加しました。テーブルを作成し、Table1
1 つのレコードを手動で に追加しましたTable1
。しかし、データを選択しようとすると、それができず、次のエラーが発生します。
データが存在しない場合の無効な読み取り試行
これは私のコードです:
SqlCommand objcomand = new SqlCommand();
SqlConnection con = new SqlConnection();
con.ConnectionString=@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\EHSAN\My Documents\Visual Studio 2010\Projects\report\report\App_Data\report.mdf;Integrated Security=True;User Instance=True";
objcomand.Connection = con;
objcomand.CommandText = "select * from Table1";
con.Open();
SqlDataReader reader1 = objcomand.ExecuteReader();
string i = reader1.GetValue(1).ToString();
con.Close();