注册 登录
编程论坛 ASP.NET技术论坛

怎样直接把textbox中(时间)内容作为条件在sql中引用

小丐帮 发布于 2012-06-19 14:43, 661 次点击
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim name As String
        name = Server.MapPath("财管.mdb")
        Dim lian As OleDbConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & name)
        lian.Open()
        Dim sql4 As String
        Dim a As Date
        sql4 = "select sum(消费额) as 和 from 消费 where 时间='"textbox1.text"'"
        Dim ming4 As New OleDbCommand(sql4, lian)
        Dim read4 As OleDbDataReader = ming4.ExecuteReader
        read4.Read()
        TextBox3.Text = read4("和")
        lian.Close()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Text = Today
    End Sub

该段代码中sql4 = "select sum(消费额) as 和 from 消费 where 时间='"textbox1.text"'"
这一句错误,请问各位大侠怎样直接把textbox1.text的内容作为条件在sql中使用
谢谢
4 回复
#2
小丐帮2012-06-19 14:46
问题补充,老提示数据类型不匹配
#3
fengjunfu2012-06-20 22:59
where 时间='"+this.textbox1.text.ToString()+"'"
这样应该就可以了
#4
absentlyh2012-06-29 09:06
少& 吧
#5
absentlyh2012-06-29 09:07
时间='" & textbox1.text & "'"
1