0
MySql.Data.MySqlClient.MySqlDataReader r = null;
MySql.Data.MySqlClient.MySqlCommand cmd = null;
System.Data.IDataRecord summary = null;

try
{
    connection.Open();
    cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM db.subnets WHERE name='"+selected+"';", connection);
    r = cmd.ExecuteReader();
    r.Read();
    summary = (System.Data.IDataRecord)r;

    <p style="font-family: 'Segoe UI'; font-size: 20px; color: #808080; margin: 0px 0px 20px 0px">Edycja podsieci</p>
    <form action="Edit.cshtml" style="color: #fff; font-family: 'Segoe UI'" method="post">
        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Nazwa:</a><input style="width: 230px" type="text" name="name" value="@summary.GetString(8)"><br>
        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Adres:</a><input style="width: 230px" type="text" name="address" value="@summary.GetString(1)"><br>
        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Maska podsieci:</a><input style="width: 230px" type="text" name="netmask" value="@summary.GetString(2)"><br>
        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Adres rozgloszeniowy:</a><input style="width: 230px" type="text" name="broadcast_address" value="@summary.GetString(4)"><br>
        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Router:</a><input style="width: 230px" type="text" name="routers" value="@summary.GetString(5)"><br>

        <a style="width: 201px; display: inline-block; margin-bottom: 7px">Serwer:</a>
        @{
            MySql.Data.MySqlClient.MySqlCommand com = null;
            MySql.Data.MySqlClient.MySqlDataReader rd = null;
            System.Data.IDataRecord rec = null;

            try
            {
                MySql.Data.MySqlClient.MySqlConnection connect = new MySql.Data.MySqlClient.MySqlConnection(connString);
                com = new MySql.Data.MySqlClient.MySqlCommand("SELECT id,name from db.servers WHERE name!="+summary.GetString(8), connection);
                rd = cmd.ExecuteReader();
                summary = (System.Data.IDataRecord)rd;

                <select style="width: 234px" name="server">
                    <option value="@summary.GetString(0)">@summary.GetString(8)</option>
                    @{
                        while(rd.Read())
                        {
                            rec = (System.Data.IDataRecord)rd;

                            <option value="@rec.GetString(0)">@rec.GetString(1)</option>
                        }
                    }
                </select>

            }
            catch(Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                rd.Close();
            }
        }

        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Budynek:</a><input style="width: 230px" type="text" name="building" value="@summary.GetString(7)"><br>
        <a style="width: 205px; display: inline-block; margin-bottom: 7px">Zakres:</a><input style="width: 230px" type="text" name="_range" value="@summary.GetString(3)"><br>
        <input type="hidden" value="subnets" name="from">
        <input type="hidden" value="@selected" name="selected">
        <input style="left: 400px; margin-top: 8px; margin-left: 380px" type="submit" value="Edytuj">
    </form>
}
catch(Exception ex)
{
    Response.Write(ex.Message);
}
finally
{
    r.Close();
    connection.Close();
}
break;    
}

运行此代码后,我收到标题中的错误。我怎样才能解决这个问题?当我已经打开 MySqlDataReader 对象时,我需要获取一些数据。我可以存储“(System.Data.IDataRecord)r”中的数据吗,因为当我关闭“r”时,“summary”中的数据被删除了。

4

0 回答 0