首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

菜鸟遇到有关问题了。大家帮帮忙。

2013-03-19 
初学者遇到问题了。。大家帮帮忙。。。前台。。 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓!D

初学者遇到问题了。。大家帮帮忙。。。
前台。。 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <style type="text/css">
        .style1
        {
            height: 106px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    
    <div class="style1">
    
        用户名<asp:TextBox ID="TextBox1" runat="server" Height="22px"></asp:TextBox>
        密码  <asp:TextBox ID="TextBox2" runat="server" Height="22px"></asp:TextBox>
              <asp:Button ID="Button1" runat="server" Text="Button" Height="26px" Width="56px" />
              <br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            
    </div>
    </form>
</body>
</html>


后台。。 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        '创建数据库连接↓
        Dim conn As SqlConnection
        Dim comd As SqlCommand
        Dim datar As SqlDataReader
        Dim sql As String

        conn = New SqlConnection("Server=local;user id=sa;pwd=123321;database=liu")
        conn.Open()
        '执行sql语句↓
        sql = "SELECT 用户名 FROM 用户"
        comd = New SqlCommand(sql, conn)
        datar = comd.ExecuteReader()
        conn.Close()
        Label1.text = datar
    End Sub

End Class

大家帮忙看看。数据库连接对了吗?  还有就是假如我想查看那个datar到底显示的什么。。在哪可以打印出来?
[解决办法]
不对,参考msdn代码


private static void CreateCommand(string queryString,
    string connectionString)


{
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        connection.Open();

        SqlCommand command = new SqlCommand(queryString, connection);
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}", reader[0]));
        }
    }
}


[解决办法]
 If datar.Read() Then
           Label1.text = datar(字段名)
        Else

热点排行