Dim KHBHSelected As String = DataGrid1.Items(e.Item.ItemIndex).Cells(2).Text  Dim mobilephone As TextBox = CType(DataGrid1.Items(e.Item.ItemIndex).Cells(7).Controls(0), TextBox)  Dim telephone As TextBox = CType(DataGrid1.Items(e.Item.ItemIndex).Cells(8).Controls(0), TextBox)         Dim sqlstr As String        sqlstr = "update Y_KHXX  set SJHM=" + mobilephone.Text.ToString.Trim + " and DHHM=" + telephone.Text.ToString.Trim + " where KHBH=" + KHBHSelected帮忙看看这个SQL语句语法是否有误,谢谢!

解决方案 »

  1.   

    少了单引号,且 set 后不能用 and ,应为 “,”
    sqlstr = "update Y_KHXX  set SJHM='" + mobilephone.Text.ToString.Trim + "' , DHHM='" + telephone.Text.ToString.Trim + "' where KHBH='" + KHBHSelected+"'"
    如果字段是日期格式,假设输入的格式为 20060514Oracle 的写法sqlstr = "update Y_KHXX  set UpdDate=To_Date('" + UpdateDate.Text.ToString.Trim + "' ,'YYYYMMDD') , DHHM='" + telephone.Text.ToString.Trim + "' where KHBH='" + KHBHSelected+"'"
    SQL Server 的写法sqlstr = "update Y_KHXX  set CreateDate=convert(smalldatetime,'" + UpdateDate.Text.ToString.Trim + "' ,112) , DHHM='" + telephone.Text.ToString.Trim + "' where KHBH='" + KHBHSelected+"'"
      

  2.   

    樓上基本已經完全解釋了,需提醒的是字符串轉換日期格式的寫法
    convert(smalldatetime,'" + UpdateDate.Text.ToString.Trim + "' ,112)視乎你輸入的格式而定
    整型不需單引號
    nvarchar視乎情況最好加上N'',否則可能出現亂碼