一个比较郁闷的问题!!
代码如下:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" theme="Theme1" Debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import NameSpace="System.Data.OleDb"%>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myconnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & Server.MapPath("db.mdb"))
Try
myconnection.open()
Catch ex As Exception
Response.Write(ex.Message)
End Try
Select Case Me.DropDownList1.SelectedValue
Case "注册"
Try
Dim sql = "Insert INTO userinfo (username,password) Values ('" & Me.username.Text & "','" & Me.password.Text & "')"
Dim mycommand = New OleDbCommand(Sql, myconnection)
mycommand.ExecuteNonQuery()
Me.Label3.Text = "注册成功,请登陆!"
Me.username.Text = ""
Me.password.Text = ""
Catch ex As Exception
Response.Write(ex.Message)
Me.username.Text = ""
Me.password.Text = ""
Me.Label3.Text = ""
End Try
Case "登陆"
Try
Dim Sql = "select * from userinfo where username='" + Me.username.Text + "' and password='" + Me.password.Text + "'"
Dim mycommand = New OleDbCommand(Sql, myconnection)
Dim mydatereader As OleDbDataReader
mydatereader = mycommand.executereader()
If Not mydatereader.Read() Then
Me.Label3.Text = "登陆失败!"
Me.username.Text = ""
Me.password.Text = ""
Else
Me.Label3.Text = "登陆成功!"
Me.username.Text = ""
Me.password.Text = ""
End If
Catch ex As Exception
Response.Write(ex.Message)
Me.username.Text = ""
Me.password.Text = ""
Me.Label3.Text = ""
End Try
End Select
End Sub
</script><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="用户名"></asp:Label>
<asp:TextBox ID="username" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="密 码"></asp:Label>
<asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox> <br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>注册</asp:ListItem>
<asp:ListItem>登陆</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="确定" OnClick="Button1_Click" />
<asp:Label ID="Label3" runat="server" Text="" Width="106px"></asp:Label><br />
</asp:Content>代码其实很简单,不知道为什么点击"注册"的总是提示:INSERT INTO 语句的语法错误。 这样的信息!
代码如下:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" theme="Theme1" Debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import NameSpace="System.Data.OleDb"%>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myconnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & Server.MapPath("db.mdb"))
Try
myconnection.open()
Catch ex As Exception
Response.Write(ex.Message)
End Try
Select Case Me.DropDownList1.SelectedValue
Case "注册"
Try
Dim sql = "Insert INTO userinfo (username,password) Values ('" & Me.username.Text & "','" & Me.password.Text & "')"
Dim mycommand = New OleDbCommand(Sql, myconnection)
mycommand.ExecuteNonQuery()
Me.Label3.Text = "注册成功,请登陆!"
Me.username.Text = ""
Me.password.Text = ""
Catch ex As Exception
Response.Write(ex.Message)
Me.username.Text = ""
Me.password.Text = ""
Me.Label3.Text = ""
End Try
Case "登陆"
Try
Dim Sql = "select * from userinfo where username='" + Me.username.Text + "' and password='" + Me.password.Text + "'"
Dim mycommand = New OleDbCommand(Sql, myconnection)
Dim mydatereader As OleDbDataReader
mydatereader = mycommand.executereader()
If Not mydatereader.Read() Then
Me.Label3.Text = "登陆失败!"
Me.username.Text = ""
Me.password.Text = ""
Else
Me.Label3.Text = "登陆成功!"
Me.username.Text = ""
Me.password.Text = ""
End If
Catch ex As Exception
Response.Write(ex.Message)
Me.username.Text = ""
Me.password.Text = ""
Me.Label3.Text = ""
End Try
End Select
End Sub
</script><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="用户名"></asp:Label>
<asp:TextBox ID="username" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="密 码"></asp:Label>
<asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox> <br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>注册</asp:ListItem>
<asp:ListItem>登陆</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="确定" OnClick="Button1_Click" />
<asp:Label ID="Label3" runat="server" Text="" Width="106px"></asp:Label><br />
</asp:Content>代码其实很简单,不知道为什么点击"注册"的总是提示:INSERT INTO 语句的语法错误。 这样的信息!
解决方案 »
- 用ASP.Net(C#+水晶报表) PDF预览打印后如何弹出提示框
- Forms验证,总是需要频繁的登陆,不知是什么原因?
- 招聘兼职:网上酒店预订系统,信息发布系统 (asp+sql Server)顶者有分!
- 请教一初级问题
- 在线请教.数据绑定问题
- 关于web Control的制作问题
- 最近做完一个项目,是一个电子商务的平台,有点问题想问问,关于效率和资源!
- 复合控件的小问题
- DataSet缓冲时,如何为同一个页的不同实例缓冲不同的DataSet实例
- 选中dropdownlist后,怎么把值分别显示在两个textbox中
- ~~急呀!马上给分;;;》》 http如何自动跳转至https 《〈
- VS2005的二个问题
是你的insert into语句出错。-----------个性签名----------
http://www.esoftnow.com/bbs
技术论坛,欢迎光临!