查看: 1740|回复: 59
|
一些.net的问题
[复制链接]
|
|
想问问
IF..THEN..END IF 和 WHILE..END WHILE 的 logic用途。
如果我用if 和 用 while 它们之间的不同还有好坏处。
比如我的SQL是这样的
"Select * From DATA Where ID = '1'"
和
"Select * From DATA"
如果
我用 IF 在第一个的SQL和第二个的SQL的Different。
和
我用 WHIlE 在第一个的SQL和第二个的SQL的Different。
谢谢给位大大给一个意见
谢谢 |
|
|
|
|
|
|
|
发表于 22-5-2006 07:20 PM
|
显示全部楼层
很含糊的问题... if 和 while 的作用完全不同... 你想要比较的是什么? |
|
|
|
|
|
|
|

楼主 |
发表于 22-5-2006 09:08 PM
|
显示全部楼层
原帖由 goatstudio 于 22-5-2006 07:20 PM 发表
很含糊的问题... if 和 while 的作用完全不同... 你想要比较的是什么?
我想比较的是拿取data的时候。
拿一个和拿两个以上的DATA的比较问题。
如:
我要拿一个DATA那里一个比较好。
或
我要拿两个或以上的那里一个比较好呢?? |
|
|
|
|
|
|
|
发表于 23-5-2006 12:13 AM
|
显示全部楼层
原帖由 红发 于 22-5-2006 09:08 PM 发表
我想比较的是拿取data的时候。
拿一个和拿两个以上的DATA的比较问题。
如:
我要拿一个DATA那里一个比较好。
或
我要拿两个或以上的那里一个比较好呢??
拿一个的话, 就直接用 If, 超过一个的话, 就用任何一个 loop. |
|
|
|
|
|
|
|

楼主 |
发表于 23-5-2006 12:18 PM
|
显示全部楼层
原帖由 goatstudio 于 23-5-2006 12:13 AM 发表
拿一个的话, 就直接用 If, 超过一个的话, 就用任何一个 loop.
哦,这样啊。
还有一个问题
如这个
Dim myConnection As New SqlConnection(dbconn)
那个SqlConnection和OdbcConnection有什么不同呢?
是不是如果我用MSSQLServer的话我就要用SqlConnection
或
如果我用ODBC来connect DB 的话就要用OdbcConnection呢?
除了上面的两个还有其他的Connection吗?
还有最上面的import,又要如何呢??
因为我看到有一些不同的connection有不同的import哦。
可以不可以给一个list或address都可以。
谢谢 |
|
|
|
|
|
|
|
发表于 23-5-2006 01:33 PM
|
显示全部楼层
SQLConnection 是给特别给 MS SQL 用的. ODBCConnection 是给用 ODBC driver 的资料库用的, 另外还有 OLEDBConnection.
其它第三方的有 MySQL, Firebird 等.
至于要 import 什么... 你找找看 .Net Manual, 每一个 class 都有一个 namespace, import 那 namespace 就是了. |
|
|
|
|
|
|
|
发表于 23-5-2006 01:34 PM
|
显示全部楼层
SQLConnection 是给特别给 MS SQL 用的. ODBCConnection 是给用 ODBC driver 的资料库用的, 另外还有 OLEDBConnection.
其它第三方的有 MySQL, Firebird 等.
至于要 import 什么... 你找找看 .Net Manual, 每一个 class 都有一个 namespace, import 那 namespace 就是了. |
|
|
|
|
|
|
|
发表于 23-5-2006 01:34 PM
|
显示全部楼层
SQLConnection 是给特别给 MS SQL 用的. ODBCConnection 是给用 ODBC driver 的资料库用的, 另外还有 OLEDBConnection.
其它第三方的有 MySQL, Firebird 等.
至于要 import 什么... 你找找看 .Net Manual, 每一个 class 都有一个 namespace, import 那 namespace 就是了. |
|
|
|
|
|
|
|

楼主 |
发表于 23-5-2006 01:40 PM
|
显示全部楼层
原帖由 goatstudio 于 23-5-2006 01:34 PM 发表
SQLConnection 是给特别给 MS SQL 用的. ODBCConnection 是给用 ODBC driver 的资料库用的, 另外还有 OLEDBConnection.
其它第三方的有 MySQL, Firebird 等.
至于要 import 什么... 你找找看 .Net Manual, ...
谢谢goatstudio的回答。
暂时是没有问题了。 |
|
|
|
|
|
|
|

楼主 |
发表于 23-5-2006 10:47 PM
|
显示全部楼层
问题又来了
- <%@ Import NameSpace="System.Data" %>
- <%@ Import NameSpace="system.Data.odbc" %>
- <%@ Page Language="vb" Debug="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"
-
- dbcon.open()
-
- Dim cmd As New OdbcCommand(sql, dbcon)
- cmd.CommandType = CommandType.StoredProcedure
-
- Dim param As New OdbcParameter
-
- param = cmd.Parameters.Add("@uname", OdbcType.VarChar, 50)
- param.Direction = ParameterDirection.Input
- param.Value = uname
-
- Dim dr
- dr = 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()
- End Sub
- </script>
复制代码
上面的code是没有问题的也没有error出来
但是就是不知为何它就是pass不去xx.html??
lblAlert.Text是show Wrong Username
connection也是没有问题的。 |
|
|
|
|
|
|
|
发表于 24-5-2006 12:29 AM
|
显示全部楼层
根据你的 code, 要 pass 去另一页的条件只有:
Trim(dr("password")) = pwd
那么应该是不符合了... 可以用 debug trace 来 trace 一下你的 pwd 和 dr("password") 值. |
|
|
|
|
|
|
|

楼主 |
发表于 24-5-2006 09:18 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 24-5-2006 11:42 PM
|
显示全部楼层
这段好像错了...
Const sql As String = "SELECT password FROM customer WHERE customer_id = @uname"
dbcon.open()
Dim cmd As New OdbcCommand(sql, dbcon)
cmd.CommandType = CommandType.StoredProcedure
你都不是用stored procedure... 为何要把cmd.commandtype 设定成 storedprocedure 呢???
这段的logic也不对...
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
你的logic是... 如果dr.read = true... 那么就执行接下来的code(蓝色)... 如果dr.read = false的话... lblAlert.Text = "Wrong Username"... 可是如果你执行得到executereader的话... dr.read 肯定是 true 的... 也就是说... 你的logic是... 如果dr.read = false(也就是执行不到executereader)... 那么lblAlert.Text = "Wrong Username"... 这应该不是你要的吧...
[ 本帖最后由 小妞儿 于 24-5-2006 11:43 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 24-5-2006 11:48 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 25-5-2006 09:01 AM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 25-5-2006 09:17 AM
|
显示全部楼层
原帖由 goatstudio 于 25-5-2006 09:01 AM 发表
你给的网站... 问题出在那里?? 你的问题??
问题是我login不到。
username : chen
password : 123
问题还没有解决呢。 |
|
|
|
|
|
|
|

楼主 |
发表于 25-5-2006 09:18 AM
|
显示全部楼层
原帖由 小妞儿 于 24-5-2006 11:42 PM 发表
这段好像错了...
Const sql As String = "SELECT password FROM customer WHERE customer_id = @uname"
dbcon.open()
Dim cmd As New OdbcCommand(sql, d ...
我 test 看用 executereader |
|
|
|
|
|
|
|
发表于 25-5-2006 09:19 AM
|
显示全部楼层
原帖由 红发 于 25-5-2006 09:17 AM 发表
问题是我login不到。
username : chen
password : 123
问题还没有解决呢。
那你的 error message 呢? 没有 error message 无法帮你呀...
尝试用 try catch statement 看看是否能呼叫 error message? 再不然用 debug trace 来找出那里已经停止了. |
|
|
|
|
|
|
|

楼主 |
发表于 25-5-2006 09:56 AM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 26-5-2006 01:03 PM
|
显示全部楼层
发现这里有问题改了一改
Dim dr
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dim dr as odbcdatareader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
但是结果还是一样。
还有小妞儿
昨天我online check一下,看到其他的人也是有用这个的
cmd.CommandType = CommandType.StoredProcedure
但是他们是connect去MSSqlServer的。。。。。。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|