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
是SqlDataReader
sdr[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