请在每次将表单注册到数据库时都需要帮助,它说注册成功,但是表单中的最后一个表(TRANSACTION表)数据信息未在数据库中输入信息,仅表FORM和STUDENT具有来自我的表格。我的交易代码有什么问题吗?还是在数据库中? 请帮助:((
sql = "INSERT INTO FORM VALUES ('" & txtformnum.Text & "' , '" & bcboRequest.Text & "' , '" & txtTotal.Text & "')"
da = New OleDb.OleDbDataAdapter(sql, con) '"
da.Fill(ds, "FORM")
sql = "INSERT INTO STUDENTS VALUES ('" & txtstudnum.Text & "','" & txtSurname.Text & "','" & txtGName.Text & "', '" & txtMName.Text & "', '" & txtAddress.Text & "', '" & status & "' , '" & txtYr.Text & "' , '" & cbostype.Text & "' , '" & chkClearance.Text & "', '" & txtCourse_Track.Text & "' , '" & txtCNumber.Text & "' , '" & dot.Value & "' , '" & dotdue.Value & "')"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "STUDENTS")
Dim sqlquery As String = "INSERT INTO TRANSACTION (Transaction_num,Stud_num,Form_num,Total Fee)" + "VALUES (" & txttransactionno.Text & ",'" & txtstudnum.Text & "'," & txtformnum.Text & "," & txtTotal.Text & ");"
Dim sqlcommand As New OleDb.OleDbCommand(sqlquery)
答案 0 :(得分:1)
我不知道您使用的是哪个数据库,但是如果您使用的是MySQL或MS SQL Server,则保留关键字TRANSACTION,并且必须对其进行转义才能在语句中使用。
如果使用MySQL,请尝试将语句更改为INSERT INTO "TRANSACTION"
如果使用SQL Server,请将您的语句更改为INSERT INTO [TRANSACTION]
如果您不使用其中任何一个,请张贴您正在使用的数据库系统,然后我将张贴适当的转义语法。
答案 1 :(得分:0)
尝试更改此行
Dim sqlquery As String = "INSERT INTO TRANSACTION (Transaction_num,Stud_num,Form_num,Total Fee)" + "VALUES (" & txttransactionno.Text & ",'" & txtstudnum.Text & "'," & txtformnum.Text & "," & txtTotal.Text & ");"
收件人
Dim sqlquery As String = "INSERT INTO TRANSACTION ([Transaction_num],[Stud_num],[Form_num],[Total Fee]) " + "VALUES ('" & txttransactionno.Text & "','" & txtstudnum.Text & "','" & txtformnum.Text & "','" & txtTotal.Text & "');"
这应该很好。
答案 2 :(得分:0)
在代码中添加以下内容:
sqlcommand.ExecuteNonQuery()