I'm getting an Data type mismatch in criteria expression error when I run the following statement, I've picked it apart and cant for the life of me see where it's going wrong ! Likely due to my beginner level of knowledge, but it's to the best of my ability!
Here's my code ;
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim UserName As String
UserName = System.Environment.UserName
Dim Month = Date.Now.ToString("MM")
Dim CS As ConnectionStringSettings = ConfigurationManager.ConnectionStrings("ConnCIM")
Dim Table As New DataTable
Dim Adapt As New OleDbDataAdapter("SELECT [LoginName], [DisplayName], [Date], [SessionID], [The wait time was acceptable] , [The length of the chat session was appropriate] , [Professionalism of the agent] , [Effectiveness of the response] , [Overall opinion of the chat service] , [Related Comments] , [Not Resolved Comments] FROM [Chat_Dump] WHERE (([LoginName] = @UserName) AND ([Date] = @Month))", CS.ToString())
Adapt.SelectCommand.Parameters.AddWithValue("@UserName", Textbox1.text)
Adapt.SelectCommand.Parameters.AddWithValue("@Month", TextBox2.Text)
TextBox2.Text = Month
Adapt.Fill(Table)
GridView1.DataSource = Table
GridView1.DataBind()
End Sub
The textbox's are there for testing only,textbox 1 gets replaced with UserName and I want textbox2 to be replaced by Month.
In short, I have a table of data that when each user views, I want it to pull their username from domain login and display their records for the current month.
Thanks! and sorry for my low level of knowledge!
If [Date]
is a DATETIME
you need to extract the month from it, then compare to your month value.
... AND MONTH([Date]) = @Month
(The integer DateTime.Now.Month
is a better choice that ToString("MM")
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.