會員資料怎麼載入資料庫

Sub writeintodata()

Dim Conn As OleDbConnection, Cmd As OleDbCommand

Dim Rd As OleDbDataReader, SQL As String

Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"

Dim Database = "Data Source=" & Server.MapPath("aaMember.mdb")

Conn = New OleDbConnection(Provider & ";" & Database)

Conn.Open()

' 寫入資料

SQL = "INSERT INTO data (userId, name, add, tel, email) VALUES ('?', '?', '?', '?', '?')"

Cmd = New OleDbCommand(SQL, Conn)

Cmd.Parameters.Add(New OleDbParameter("@userId", OleDbType.Char, 255))

Cmd.Parameters.Add(New OleDbParameter("@name", OleDbType.Char, 255))

Cmd.Parameters.Add(New OleDbParameter("@add", OleDbType.Char, 255))

Cmd.Parameters.Add(New OleDbParameter("@tel", OleDbType.Char, 255))

Cmd.Parameters.Add(New OleDbParameter("@email", OleDbType.Char, 255))

Cmd.Parameters(0).Value = UserID.Text

Cmd.Parameters(1).Value = name.Text

Cmd.Parameters(2).Value = add.Text

Cmd.Parameters(3).Value = tel.Text

Cmd.Parameters(4).Value = email.Text

Cmd.ExecuteNonQuery()

Msg.Text = "資料處理完畢,您已經成為本站的會員!"

Conn.Close()

Rd.Close()

End Sub

程式如以上

run 時他說是insert into 陳述句有問題

但是查了一下asp的課本 是這樣子寫沒錯呀

幫幫我找一下錯在哪裡>""<

謝謝大家!!!

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    如果你用的是ASP .Net2.0語法[VB.Net 2005開發]應該是

    SQL = "INSERT INTO data (userId, name, add, tel, email) VALUES (?, ?, ?, ?, ?)" '?不可用單引號包住

    如果你用的是ASP .Net1.x語法[VB.Net 2003開發]應該是

    SQL = "INSERT INTO data (userId, name, add, tel, email) VALUES (@userId, @name, @add, @tel, @email)"

Still have questions? Get your answers by asking now.