我的xs表中有如下几个字段: 学号  char  
                           姓名 char 
                            性别  char  
                            分数  int    
                        出生日期  datetimePrivate Sub Command1_Click()
Dim com As New ADODB.Command
Dim name As String  '学生姓名
Dim sex As String '学生性别
Dim score As  integer
Dim age As date 
Dim sql As String
name = Trim(Text1.Text)
sex = Trim(Text2.Text)
score = Trim(Text3.Text)
age = Trim(Text4.Text)
Set com.ActiveConnection = connsql = "update sp set 分数=score where 姓名=name and 出生日期=age"
com.CommandText = sql
com.Execute  这个update 语句无法实现,请教各位该如何去改!在线急等

解决方案 »

  1.   

    sql = "update sp set 分数='" & score & "' where 姓名='" & name  & "' and 出生日期='" & age & "'"
      

  2.   

    那个分数字段在表中是int 型的,而我在VB的文本框中输入的可是字符串型的,怎么可以把字串型给转换成int 型?
      

  3.   

    我把cint(score)放在了UPDATE语句里出了CINT不是可以识别的函数名.
    sql = "update sp set 分数= cint(score)  where 姓名='" & name  & "' and 出生日期='" & age & "'"
      

  4.   

    sql = "update sp set 分数='" & cint(score) & "' where 姓名='" & name  & "' and 出生日期='" & age & "'"
      

  5.   

    CCur(string)
    这么多问题是不是得多给点分啊
      

  6.   

    报错了
    SQL SERVER不允许从数据类型varchar 到数据类型 money的隐性转换
      

  7.   

    sql = "update sp set 分数=cast('" & score & "' as int) where 姓名='" & name  & "' and 出生日期='" & age & "'"
    ----------------------
    用CAST函数,cint是VB中的函数,而且是转换成INTERGER数据类型,SQL中的INT在VB中要用LONG。另外,只要你能保证你的score = Trim(Text3.Text)符合数值格式规定,那么在SQL语句用不用CAST都无所谓,即便你在VB应用程序发往数据库端前,用CLNG或者CINT转换一下,传递到数据库端的还不一样都是字符?要知道你传递的是sql这个字符串啊,打个不文雅的比喻请别生气“这叫做脱了裤子放屁……”,您实在要按数据类型由应用程序向数据库传递数据,你不如做个UPDATE的存储过程。