简体   繁体   English

oracle vb.net数据集填充

[英]oracle vb.net dataset fill

What is wrong with this code? 此代码有什么问题? No error, but no results. 没有错误,但没有结果。 My DataGridView_sent does not get filled. 我的DataGridView_sent没有填充。

Dim objConn As New System.Data.OracleClient.OracleConnection
Dim objCmd As New System.Data.OracleClient.OracleCommand
Dim dtAdapter As New System.Data.OracleClient.OracleDataAdapter

Dim ds As New DataSet
Dim strConnString, strSQL As String

strConnString = "Data Source=db;User Id=user;Password=pass;"
strSQL = "select * from table where sentdate between '" & date1 & "' and '" & date2 & "'"

 objConn.ConnectionString = strConnString
 With objCmd
     .Connection = objConn
     .CommandText = strSQL
     .CommandType = CommandType.Text
  End With
  dtAdapter.SelectCommand = objCmd

  dtAdapter.Fill(ds)
  DataGridView_sent.DataSource = ds

  dtAdapter = Nothing
  objConn.Close()
  objConn = Nothing

This is probably caused by incorrect representation of dates. 这可能是由于日期表示不正确引起的。
You should use parametrized queries and let the Oracle Provider render in the correct mode your date fields values 您应该使用参数化查询,并让Oracle Provider以正确的方式呈现您的日期字段值

....
strSQL = "select * from table where sentdate between :date1 and :date2" 
objConn.ConnectionString = strConnString 
With objCmd 
   .Connection = objConn 
   .CommandText = strSQL 
   .CommandType = CommandType.Text 
   .Parameters.AddWithValue(":date1", Convert.ToDateTime(date1));
   .Parameters.AddWithValue(":date2", Convert.ToDateTime(date2));
End With 
dtAdapter.SelectCommand = objCmd 
.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM