私はSQL ServerからC#に日付を取得しようとしています。私はそれをすることができませんでした。データベースに日時データを取得するには?
私は日付を取得できません。私はちょうどMM/DD/YY
のような日付情報が必要で、06/26/2009 00:00:00:000
のようではなく、時間情報は必要ありません。
このコマンドテキストをSQL Serverで試すと、機能します。
私はこのコードをしようとすると、
date = drr["Tarih"].toString();
部分で、私はエラー
System.IndexOutOfRangeException
コードを取得:
SqlConnection con;
SqlCommand cmd;
string date;
public string getDate(int noo, int idd)
{
int no = noo;
int id = idd;
con = new SqlConnection(@"Data Source=AHMET\SQLEXPRESS; Initial Catalog=yoklama; Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select Max(Tarih) from Yoklama where Ogrenci_NO = '" + no + "' and Ders_ID = '" + id + "' ";
try
{
con.Open();
SqlDataReader drr = cmd.ExecuteReader();
while(dr.Read()) {
date = drr["Tarih"].ToString();
}
}
catch (SqlException)
{
// error here
}
finally
{
con.Close();
}
return date;
}
を。戻り値の型はintです。 tarih = dr ["Tarih"];仕事でさえ?私はあなたがどこに接続を開くか分からない。書式を修正します。 – Paparazzi
それは私の悪いことでした、私は多くのことを試しました、私はそれを修正することを忘れないでください – Ahmet
その後、質問を修正します。そして、書式を修正してください。答えは質問と同じくらい良いです。あなたが質問を解決しないと、これは終了する可能性が高いです。 – Paparazzi