dateTimePicker2.Value = Convert.ToDateTime((sdr[1]),
CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
SqlDataReader から日付値を取得していますが、それを読み取るとエラーが発生します。
インデックスが配列の範囲外だった
cmd = new SqlCommand("Physio_cure_Search", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@RegisterNo", SqlDbType.VarChar).Value = txtsearch.Text;
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
txtregistrationno.Text = sdr.GetString(0);
//giving error on this line:
dateTimePicker2.Value = Convert.ToDateTime((sdr[1]), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
}
sdr
これは のインスタンスで、 sdr SqlDataReader
[1] はデータベース値を取得するために使用されます。これはどのように修正できますか?
ALTER procedure [dbo].[Physio_cure_Search]
@RegisterNo varchar(500)
As
begin
select Convert(varchar(100),DateOfBirth,103) as DateOfBirth
from Physio_cureTable
select RegisterNo,RegistrationDate,Stimulation,PationName,DateOfBirth,ContactNo,Occupation,Age,
Sex,Weight,Chief_Complain,Investigation_Result,PastHistoryAny,Physical_Examination,Ref_By_Doctor,Medications,Prognosis,Electro_Therapy,Neuro_Rehabilitation,Ortho_Rehabilitation,Cardio_Pulmonery_Rehabilitation,Sports_Rehabilitation
from Physio_cureTable where RegisterNo=@RegisterNo and Syncoperation <>'D'
end