程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何从SQL检索和显示数据到Aspx Webform大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何从SQL检索和显示数据到Aspx Webform?

开发过程中遇到如何从SQL检索和显示数据到Aspx Webform的问题如何解决?下面主要结合日常开发的经验,给出你关于如何从SQL检索和显示数据到Aspx Webform的解决方法建议,希望对你解决如何从SQL检索和显示数据到Aspx Webform有所启发或帮助;

看看这个msdn教程:使用DataReader检索数

        sqlDataReader rdr = null;
        sqlConnection con = null;
        sqlCommand cmd = null;

        try
        {
            // Open connection to the database
            String ConnectionString = "server=xeon;uID=sa;"+
                "pwd=manager; database=northwind";
            con = new sqlConnection(ConnectionString);
            con.open();

            // Set up a command with the given query and associate
            // this with the current connection.
            String CommandText = "SELECT Firstname, Lastname" +
                                 "  FROM employees" +
                                 " WHERE (Lastname liKE @Find)";
            cmd = new sqlCommand(CommandText);
            cmd.Connection = con;

            // Add Lastname to the above defined paramter @Find
            cmd.Parameters.Add(
                new sqlParameter(
                "@Find", // The name of the parameter to map
                System.Data.sqlDbType.NVarChar, // sqlDbType values
                20, // The wIDth of the parameter
                "Lastname"));  // The name of the source @R_262_8620@n

            // Fill the parameter with the value retrIEved
            // from the text fIEld
            cmd.Parameters["@Find"].Value = txtFind.Text;

            // Execute the query
            rdr = cmd.ExecuteReader();

            // Fill the List Box with the values retrIEved
            lbFound.Items.Clear();
            while(rdr.Read())
            {
                lbFound.Items.Add(rdr["Firstname"].ToString() +
                " " + rdr["Lastname"].ToString());
            }
        }
        catch(Exception eX)
        {
            // Print error message
            messageBox.Show(ex.messagE);
        }
        finally
        {
            // Close data reader object and database connection
            if (rdr != null)
                rdr.Close();

            if (con.State == ConnectionState.open)
                con.Close();
        }

解决方法

我是in.net的新手,我尝试创建一个简单的网站。

我有一个多行文本框,并具有固定的宽度和高度。

<asp:TextBox ID="TextBox1" runat="server" Height="168px" TextMode="MultiLine" 
                            Width="303px"></asp:TextBox>

我还创建了一个web.config来连接到我的sql数据库:

<connectionStrings>
<add name="TDBSConnectionString" connectionString="Data source=local;Initial Catalog=IBSI;Persist Security Info=True;User ID=sa;password=1"
  providerName="System.Data.SqlClient" />

我如何从数据库中检索数据并将内容显示在上面的文本框中。我使用多行,因为数据不止一个。

大佬总结

以上是大佬教程为你收集整理的如何从SQL检索和显示数据到Aspx Webform全部内容,希望文章能够帮你解决如何从SQL检索和显示数据到Aspx Webform所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。