タイトル | : Re^3: VBからAccessのデータベースの一部を更新するには? |
記事No | : 2592 |
投稿日 | : 2005/11/15(Tue) 10:48 |
投稿者 | : なおこ(・∀・) |
お世話になります。
こんな感じでいかがでしょう。 <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) ' ページを初期化するユーザー コードをここに挿入します。 If Not IsPostBack Then 'ID用テキストボックス Me.TextBox1.Text = "" 'Password用テキストボックス Me.TextBox2.Text = "" 'ログインボタン Me.Button1.Text = "ログイン" 'メッセージ表示用 Me.Label1.Text = "" End If End Sub Sub Button1_Click(sender As Object, e As EventArgs) If Me.AddCheck(1, Me.TextBox1.Text, Me.TextBox2.Text) > 0 Then Me.Label1.Text = "ログインしました" Else Me.Label1.Text = "該当ユーザーが見つかりませんでした" End If End Sub Private Function AddCheck(ByVal check As Integer, _ ByVal id As String, _ ByVal pass As String) As Integer Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\test\db1.mdb" Dim oleConnection As System.Data.OleDb.OleDbConnection oleConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim updateCommand As System.Data.OleDb.OleDbCommand updateCommand = New System.Data.OleDb.OleDbCommand updateCommand.Connection = oleConnection updateCommand.CommandType = System.Data.CommandType.Text updateCommand.CommandText = "UPDATE Users SET Users.Check=@Check WHERE ID=@ID AND Password=@Password;" Dim param_check As System.Data.OleDb.OleDbParameter param_check = New System.Data.OleDb.OleDbParameter param_check.OleDbType = System.Data.OleDb.OleDbType.Integer param_check.Value = check updateCommand.Parameters.Add(param_check) Dim param_id As System.Data.OleDb.OleDbParameter param_id = New System.Data.OleDb.OleDbParameter param_id.OleDbType = System.Data.OleDb.OleDbType.VarChar param_id.Value = id updateCommand.Parameters.Add(param_id) Dim param_pass As System.Data.OleDb.OleDbParameter param_pass = New System.Data.OleDb.OleDbParameter param_pass.OleDbType = System.Data.OleDb.OleDbType.VarChar param_pass.Value = pass updateCommand.Parameters.Add(param_pass) Dim rowsAffected As Integer = 0 oleConnection.Open() Try rowsAffected = updateCommand.ExecuteNonQuery() Return rowsAffected Finally updateCommand.Dispose() oleConnection.Close() End Try End Function
</script> <html> <head> </head> <body> <form runat="server"> <table> <tbody> <tr> <td> <asp:TextBox id="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:TextBox id="TextBox2" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button> </td> </tr> </tbody> <tbody> <tr> <td> <asp:Label id="Label1" runat="server" width="409px">Label</asp:Label></td> </tr> </tbody> </table> </form> </body> </html>
|