数据表中有cust_id,cust_name,cust_data三个字段,在窗体中有text1,text2,text3
在VB中怎样利用insert into将三个文本框中的数据提交到表中的相应字段中,怎样写代码包括(VB语句和SQL语句)将三个文本框中的值提交到相应字段中。

解决方案 »

  1.   

    '如果cust_data为字符型:
      conn.execute " insert into customer(cust_id,cust_name,cust_data) values('"& text1.text &"','"& text2.text &"','"& text3.text &"')"
    '如果cust_data为数值型:
      conn.execute " insert into customer(cust_id,cust_name,cust_data) values('"& text1.text &"','"& text2.text &"',"& text3.text &")"
      

  2.   

    dim sqlsql="insert into table(cust_id,cust_name,cust_data) values("
    sql=sql & "'"&text1.text&"',"
    sql=sql & "'"&text2.text&"',"
    sql=sql & "'"&text3.text&"')"con.execute(sql)
      

  3.   

    Dim DB As New Connection 
    DB.ConnectionString="连接数据库的字符串"
    DB.Open '如果已连好的话可以不写
    Dim C as New Command
    C.ActiveConnection=DB
    C.CommandType=adCmdText
    C.CommandType="insert into customer(cust_id,cust_name,cust_data) values('"& text1.text &"','"& text2.text & "','" & text3.text & "'"
    C.Execute