当我运行以下声明时,我在条件表达式错误中遇到数据类型不匹配,我已经把它拆开了,并且因为我的生活无法看出它出了什么问题!可能由于我的初学者知识水平,但它尽我所能!
这是我的代码;
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
文本框仅用于测试,文本框1替换为UserName,我希望textbox2替换为Month。
简而言之,我有一个数据表,当每个用户查看时,我希望它从域登录中提取用户名并显示当前月份的记录。
谢谢!抱歉我的知识水平很低!
答案 0 :(得分:0)
如果[Date]
是DATETIME
,您需要从中提取月份,然后与月份值进行比较。
... AND MONTH([Date]) = @Month
(整数DateTime.Now.Month
是ToString("MM")
)