如何使用vb.net中datetimepicker控件的日期值搜索行 [英] how to search for rows using date value from datetimepicker control in vb.net
本文介绍了如何使用vb.net中datetimepicker控件的日期值搜索行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用vb.net和sql server。这是我使用datetimepicker控件中的日期值搜索行的代码。问题是,即使我输入数据库中已存在的日期值,我仍然没有得到任何行。问题是什么?它与日期值的格式有关吗?
sqlsearch = 从学生中选择*,其中student_dob = @ dob
Dim da < span class =code-keyword> As 新 SqlDataAdapter(sqlsearch,con)
da.SelectCommand.Parameters.AddWithValue( @ dob,DateTimePicker1.Value)
da.Fill(ds)
con。关闭()
如果 ds.Tables( 0 )。Rows.Count = 0 然后
MessageBox.Show( 不存在记录,请重试, 抱歉! ,MessageBoxButtons.OK)
其他
po pulate_lvw1()
结束 如果
解决方案
将DateTimePicker的日期值设置如下
da.SelectCommand.Parameters.AddWithValue( @ dob,DateTimePicker1.Value。 Date )
i am using vb.net and sql server. this is my code to search for rows using date value from a datetimepicker control. the problem is even though i enter a date value which is already there in the database i still don't get any rows. what is the problem? is it something to do with the formatting of the date values or?
sqlsearch = "Select * from Students where student_dob =@dob"
Dim da As New SqlDataAdapter(sqlsearch, con)
da.SelectCommand.Parameters.AddWithValue("@dob", DateTimePicker1.Value)
da.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count = 0 Then
MessageBox.Show("No record exists, try again", "SORRY!", MessageBoxButtons.OK)
Else
populate_lvw1()
End If
解决方案
set the Date of DateTimePicker value as below
da.SelectCommand.Parameters.AddWithValue("@dob", DateTimePicker1.Value.Date)
这篇关于如何使用vb.net中datetimepicker控件的日期值搜索行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文