佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1740|回复: 59

一些.net的问题

[复制链接]
发表于 22-5-2006 07:16 PM | 显示全部楼层 |阅读模式
想问问
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。

谢谢给位大大给一个意见
谢谢
回复

使用道具 举报


ADVERTISEMENT

发表于 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 就是了.
回复

使用道具 举报

Follow Us
发表于 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 就是了.
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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 | 显示全部楼层
问题又来了


  1. <%@ Import NameSpace="System.Data" %>
  2. <%@ Import NameSpace="system.Data.odbc" %>
  3. <%@ Page Language="vb" Debug="true" %>

  4. <script language="vb" runat="server">

  5. Sub My_click(Sender As Object,e As EventArgs)

  6.         Dim Conn As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  7.         Dim dbcon As New OdbcConnection(Conn)
  8.        
  9.         Dim uname As String = Replace(Trim(username.Text), "'", "''")
  10.         Dim pwd As String = Replace(Trim(password.Text), "'", "''")
  11.        
  12.         Const sql As String = "SELECT password FROM customer WHERE customer_id = @uname"
  13.        
  14.         dbcon.open()
  15.        
  16.         Dim cmd As New OdbcCommand(sql, dbcon)
  17.         cmd.CommandType = CommandType.StoredProcedure
  18.        
  19.         Dim param As New OdbcParameter
  20.        
  21.         param = cmd.Parameters.Add("@uname", OdbcType.VarChar, 50)
  22.         param.Direction = ParameterDirection.Input
  23.         param.Value = uname
  24.        
  25.         Dim dr
  26.         dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)     
  27.        
  28.                 If dr.Read() Then     
  29.        
  30.                         If Trim(dr("password")) = pwd Then         
  31.                                 FormsAuthentication.SetAuthCookie(uname, False)               
  32.                                 FormsAuthentication.RedirectFromLoginPage(uname, False)  
  33.                                 Response.Redirect("xx.html")           
  34.                         Else                 
  35.                                 lblAlert.Text = "Wrong password"         
  36.                         End If
  37.                
  38.                 Else     
  39.                         lblAlert.Text = "Wrong Username"        
  40.                 End If

  41.         dr.close()
  42. End Sub

  43. </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 | 显示全部楼层
原帖由 goatstudio 于 24-5-2006 12:29 AM 发表
根据你的 code, 要 pass 去另一页的条件只有:

Trim(dr("password") = pwd

那么应该是不符合了... 可以用 debug trace 来 trace 一下你的 pwd 和 dr("password" 值.


冒味的说一句。

好像连我的username都有问题的。
因为它给我的error code是username wrong。

感觉上好像一开始就错了。


但我也会在用debug trace 来 trace 一下看看的。
回复

使用道具 举报

发表于 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 | 显示全部楼层
是不是这样??

http://www.studiolibrary.com/aspx/log.aspx

我已经尽力了。
但是还是不知道那里错。
希望哪位大大可以帮个忙

小弟会以身相婿的。
回复

使用道具 举报

发表于 25-5-2006 09:01 AM | 显示全部楼层
原帖由 红发 于 24-5-2006 11:48 PM 发表
是不是这样??

http://www.studiolibrary.com/aspx/log.aspx

我已经尽力了。
但是还是不知道那里错。
希望哪位大大可以帮个忙

小弟会以身相婿的。


你给的网站... 问题出在那里?? 你的问题??
回复

使用道具 举报

 楼主| 发表于 25-5-2006 09:17 AM | 显示全部楼层
原帖由 goatstudio 于 25-5-2006 09:01 AM 发表


你给的网站... 问题出在那里?? 你的问题??


问题是我login不到。
username : chen
password : 123

问题还没有解决呢。
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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 | 显示全部楼层
原帖由 goatstudio 于 25-5-2006 09:19 AM 发表


那你的 error message 呢? 没有 error message 无法帮你呀...
尝试用 try catch statement 看看是否能呼叫 error message? 再不然用 debug trace 来找出那里已经停止了.


我也不知道为何他没有error message


也问了其他的人没有人知道为何
回复

使用道具 举报

 楼主| 发表于 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的。。。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 5-8-2025 06:44 AM , Processed in 0.133163 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表