|
发表于 26-5-2006 01:44 PM
|
显示全部楼层
原帖由 红发 于 26-5-2006 01:03 PM 发表
还有小妞儿
昨天我online check一下,看到其他的人也是有用这个的
cmd.CommandType = CommandType.StoredProcedure
但是他们是connect去MSSqlServer的。。。。。。
别人用 cmd.CommandType = CommandType.StoredProcedure 是因为别人用stored procedure... 可是你不是... 事实把这段delete掉(在你的code没必要放这段)... 然后再run... 因该没问题... |
|
|
|
|
|
|
|

楼主 |
发表于 26-5-2006 11:47 PM
|
显示全部楼层
原帖由 小妞儿 于 26-5-2006 01:44 PM 发表
别人用 cmd.CommandType = CommandType.StoredProcedure 是因为别人用stored procedure... 可是你不是... 事实把这段delete掉(在你的code没必要放这段)... 然后再run... 因该没问题...
结果还是一样。。。。 |
|
|
|
|
|
|
|
发表于 26-5-2006 11:52 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-5-2006 12:51 AM
|
显示全部楼层
- <%@ Import NameSpace="System.Data" %>
- <%@ Import NameSpace="system.Data.odbc" %>
- <%@ Page Language="vb" Debug="true" trace="true" %>
- <script language="vb" runat="server">
- Sub My_click(Sender As Object,E As EventArgs)
- Dim Conn As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
- Dim dbcon As New OdbcConnection(Conn)
-
- Dim uname As String = Replace(Trim(username.Text), "'", "''")
- Dim pwd As String = Replace(Trim(password.Text), "'", "''")
-
- Const sql As String = "SELECT password FROM customer WHERE customer_id = @uname;"
-
- Dim cmd As New OdbcCommand(sql, dbcon)
-
- dbcon.open()
-
- Dim param As New OdbcParameter
-
- param = cmd.Parameters.Add("@uname", OdbcType.VarChar, 50)
- param.Direction = ParameterDirection.Input
- param.Value = uname
-
- Dim dr As OdbcDataReader = cmd.ExecuteReader()
-
- If dr.Read() Then
-
- If Trim(dr("password")) = pwd Then
- FormsAuthentication.SetAuthCookie(uname, False)
- FormsAuthentication.RedirectFromLoginPage(uname, False)
- Response.Redirect("xx.html")
- Else
- lblAlert.Text = "Wrong password"
- End If
-
- Else
- lblAlert.Text = "Wrong Username"
- End If
- dr.close()
- dbcon.close()
-
- Response.write(uname)
- Response.write("<br>")
- Response.write(pwd)
- End Sub
- </script>
- <html>
- <head>
- <meta http-equiv="Content-Language" content="en-us">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Login</title>
- </head>
- <body>
- <form runat="server">
- <table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
- <tr>
- <td width="104"> </td>
- <td><asp:Label ID="lblAlert" Runat="server" Text="Please Key In Username And Password"/></td>
- </tr>
- <tr>
- <td width="104">username</td>
- <td><asp:TextBox ID="username" Runat="server" Columns="20"/></td>
- </tr>
- <tr>
- <td width="104">password</td>
- <td><asp:TextBox ID="password" Runat="server" Columns="20"/></td>
- </tr>
- <tr>
- <td colspan="2"><asp:Button id="My" runat="server" OnClick="My_click" Text="Login"/>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
复制代码
web.config的
- <configuration>
- <appSettings/>
- <connectionStrings>
- <add name="ConnectionString" connectionString="Dsn=mydata;uid=root77;pwd=chen1983"
- providerName="System.Data.Odbc" />
- </connectionStrings>
- </configuration>
复制代码
我用VS 2005 debug过没有问题
------ Build started: Project: http://localhost/WebSite5/, Configuration: Debug .NET ------
Validating Web Site
Building directory '/WebSite5/'.
Validation Complete
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
就是不知道那里错。
那位大大可以教教小弟。
还是帮我看看我的code那里miss掉了。
谢谢各位 |
|
|
|
|
|
|
|
发表于 27-5-2006 09:30 AM
|
显示全部楼层
奇怪了... 我把你的整段code copy去新的file...然后改了database的部分(我用access)... 也根据你的web.config改为acess适用的... 根本没问题... 可以redirect去xx.html和显示wrong username, wrong password... 你是不是记错username and password了?? |
|
|
|
|
|
|
|

楼主 |
发表于 27-5-2006 11:36 AM
|
显示全部楼层
原帖由 小妞儿 于 27-5-2006 09:30 AM 发表
奇怪了... 我把你的整段code copy去新的file...然后改了database的部分(我用access)... 也根据你的web.config改为acess适用的... 根本没问题... 可以redirect去xx.html和显示wrong username, wrong password... 你 ...
这就不可能了,我的database是同一个的。username 和 password 也是一样的。
你是不是也是用odbc来connect呢?? |
|
|
|
|
|
|
|
发表于 27-5-2006 11:43 AM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-5-2006 02:18 PM
|
显示全部楼层
原帖由 小妞儿 于 27-5-2006 11:43 AM 发表
我用oledb...
那可以看看你的code吗?? |
|
|
|
|
|
|
|

楼主 |
发表于 27-5-2006 02:55 PM
|
显示全部楼层
刚刚做了一个delete的
发现他也不能delete data的。。。
不知道是不是pass values时有错误。
再看看
- <%@ Import NameSpace="System.Data" %>
- <%@ Import NameSpace="system.Data.odbc" %>
- <%@ Page Language="vb" Debug="true" trace="true" %>
- <script language="vb" runat="server">
- Sub My_click(Sender As Object,E As EventArgs)
- Dim Conn As String = ConfigurationManager.ConnectionStrings("Connstri").ConnectionString
- Dim dbcon As New OdbcConnection(Conn)
-
- Dim uname As String = Replace(Trim(username.Text), "'", "''")
-
- Dim sql As String = "Delete From usertable where username = @uname"
-
- Dim cmd As New OdbcCommand(sql, dbcon)
- dbcon.open()
- cmd.ExecuteNonQuery()
-
- End Sub
- </script>
- <html>
- <head>
- <meta http-equiv="Content-Language" content="en-us">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Login</title>
- </head>
- <body>
- <form runat="server">
- <table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
- <tr>
- <td width="104"> </td>
- <td><asp:Label ID="lblAlert" Runat="server" Text="Please Key In Username And Password"/></td>
- </tr>
- <tr>
- <td width="104">username</td>
- <td><asp:TextBox ID="username" Runat="server" Columns="20"/></td>
- </tr>
- <tr>
- <td width="104">password</td>
- <td><asp:TextBox ID="password" Runat="server" Columns="20"/></td>
- </tr>
- <tr>
- <td colspan="2"><asp:Button id="My" runat="server" OnClick="My_click" Text="Login"/>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
复制代码
[ 本帖最后由 红发 于 27-5-2006 03:01 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 27-5-2006 05:06 PM
|
显示全部楼层
原帖由 红发 于 27-5-2006 02:18 PM 发表
那可以看看你的code吗??
- <%@ Page Language="vb" Debug="true" %>
- <%@ import Namespace="System.Data" %>
- <%@ import Namespace="system.Data.oledb" %>
- <script runat="server">
- Sub My_click(Sender As Object,E As EventArgs)
-
- Dim Conn As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
- Dim dbcon As New oledbConnection(Conn)
-
- Dim uname As String = Replace(Trim(username.Text), "'", "''")
- Dim pwd As String = Replace(Trim(password.Text), "'", "''")
-
- Const sql As String = "SELECT password FROM useracc where username=@uname"
-
- Dim cmd As New oledbCommand(sql, dbcon)
-
- dbcon.open()
-
- Dim param As New oledbParameter
-
- param = cmd.Parameters.Add("@uname", oledbType.VarChar, 50)
- param.Direction = ParameterDirection.Input
- param.Value = uname
-
- Dim dr As oledbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
-
- If dr.Read() Then
-
- If Trim(dr("password")) = pwd Then
- FormsAuthentication.SetAuthCookie(uname, False)
- FormsAuthentication.RedirectFromLoginPage(uname, False)
- Response.Redirect("xx.html")
- Else
- lblAlert.Text = "Wrong password"
- End If
-
- Else
- lblAlert.Text = "Wrong Username"
- End If
-
- dr.close()
- dbcon.close()
-
- Response.write(uname)
- Response.write("<br>")
- Response.write(pwd)
- End Sub
- </script>
- <html>
- <head>
- <title>Login</title>
- <meta http-equiv="Content-Language" content="en-us" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <form runat="server">
- <table id="table1" cellspacing="0" cellpadding="0" width="100%" border="0">
- <tbody>
- <tr>
- <td width="104">
- </td>
- <td>
- <asp:Label id="lblAlert" runat="server" text="Please Key In Username And Password"></asp:Label></td>
- </tr>
- <tr>
- <td width="104">
- username</td>
- <td>
- <asp:TextBox id="username" Columns="20" Runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td width="104">
- password</td>
- <td>
- <asp:TextBox id="password" Columns="20" Runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <asp:Button id="My" onclick="My_click" runat="server" Text="Login"></asp:Button>
- </td>
- </tr>
- </tbody>
- </table>
- </form>
- </body>
- </html>
复制代码
- <?xml version="1.0" encoding="UTF-8" ?>
- <configuration>
- <connectionStrings>
- <add name="connectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\ASP.Net\Blog\blog.mdb"
- providerName="system.data.oledb" />
- </connectionStrings>
- </configuration>
复制代码 |
|
|
|
|
|
|
|
发表于 27-5-2006 05:16 PM
|
显示全部楼层
原帖由 红发 于 27-5-2006 02:55 PM 发表
刚刚做了一个delete的
发现他也不能delete data的。。。
不知道是不是pass values时有错误。
再看看
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="system.Dat ...
你忘了add parameter... |
|
|
|
|
|
|
|

楼主 |
发表于 28-5-2006 10:40 PM
|
显示全部楼层
原帖由 小妞儿 于 27-5-2006 05:16 PM 发表
你忘了add parameter...
可是但我这样写的时候是可以delete我的record的哦
- Dim sql As String = "Delete From usertable where username ='"&request("username")&"'"
复制代码
但是当我这样写的时候
- tt = Request("username")
- Dim sql As String = "Delete From usertable where username ='"&tt&"'"
复制代码
就中了error了
BC30205: End of statement expected.
Dim sql As String = "Delete From usertable where username ='"&tt&"'"
这又是什么问题了呢????
上面我有放
Dim tt
or
Dim tt As String <- 觉得这个有问题
[ 本帖最后由 红发 于 28-5-2006 10:43 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 28-5-2006 10:59 PM
|
显示全部楼层
原帖由 红发 于 28-5-2006 10:40 PM 发表
tt = Request("username")
Dim sql As String = "Delete From usertable where username ='"&tt&"'"
既然 tt 已经 assigned 一个 value 了... 那么 sql 应该是
dim sql as string = "delete from usertable where username =" & tt
试试看... |
|
|
|
|
|
|
|
发表于 28-5-2006 11:07 PM
|
显示全部楼层
原帖由 红发 于 28-5-2006 10:40 PM 发表
可是但我这样写的时候是可以delete我的record的哦
Dim sql As String = "Delete From usertable where username ='"&request("username" &"'"
但是当我这样 ...
如果你的 tt 是 string 不是一个号码, 那么你也许得检查下里面有没有包含 " ' ", " " " 这些字. |
|
|
|
|
|
|
|

楼主 |
发表于 29-5-2006 09:12 AM
|
显示全部楼层
原帖由 小妞儿 于 28-5-2006 10:59 PM 发表
既然 tt 已经 assigned 一个 value 了... 那么 sql 应该是
dim sql as string = "delete from usertable where username =" & tt
试试看...
现在没有的test晚上再test看能不能
原帖由 goatstudio 于 28-5-2006 11:07 PM 发表
如果你的 tt 是 string 不是一个号码, 那么你也许得检查下里面有没有包含 " ' ", " " " 这些字.
100%是string
和
100%没有 ' and " 的东西出现 |
|
|
|
|
|
|
|

楼主 |
发表于 29-5-2006 10:58 PM
|
显示全部楼层
原帖由 小妞儿 于 28-5-2006 10:59 PM 发表
既然 tt 已经 assigned 一个 value 了... 那么 sql 应该是
dim sql as string = "delete from usertable where username =" & tt
试试看...
可惜可惜,还是不能
为何我的问题都没有什么人来回答得呢???
还是问题太容易了?? |
|
|
|
|
|
|
|
发表于 30-5-2006 01:18 AM
|
显示全部楼层
其实回到你原本的code... 只要add 一个parameter就没问题了...
你的code是这样:
Dim Conn As String = ConfigurationManager.ConnectionStrings("Connstri").ConnectionString
Dim dbcon As New OdbcConnection(Conn)
Dim uname As String = Replace(Trim(username.Text), "'", "''")
Dim sql As String = "Delete From usertable where username = @uname"
Dim cmd As New OdbcCommand(sql, dbcon)
dbcon.open()
cmd.ExecuteNonQuery()
你delete不到是因为你没add parameter
只要在Dim cmd As New OdbcCommand(sql, dbcon)下面加这行code应该就行了...
cmd.parameters.add(new odbcparameter("@uname", username.text))
再试试看... 在不行的话请该把error message贴出来... 比较容易分析... :)
[ 本帖最后由 小妞儿 于 30-5-2006 01:20 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 30-5-2006 07:34 AM
|
显示全部楼层
用parameter 还有stored procedure 就不用烦恼漏掉什么开引号,挂号的烦恼咯。。 |
|
|
|
|
|
|
|

楼主 |
发表于 30-5-2006 09:22 AM
|
显示全部楼层
原帖由 tensaix2j 于 30-5-2006 07:34 AM 发表
用parameter 还有stored procedure 就不用烦恼漏掉什么开引号,挂号的烦恼咯。。
想问一下,parameter 和 stored procedure 这两个的用处。
可以说明一下吗?
谢谢。 |
|
|
|
|
|
|
|

楼主 |
发表于 30-5-2006 09:23 AM
|
显示全部楼层
回小妞儿
不是我不要写error出来。。。
是没有error我如何写。。。。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|