vs2015 dr1 error

omerayna

New member
Joined
Sep 16, 2023
Messages
1
Programming Experience
Beginner
HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="onurty.aspx.cs" Inherits="JOIN_PROJEM.onurty" %>

<!DOCTYPE html>

<html xmlns="[URL='http://www.w3.org/1999/xhtml']XHTML namespace[/URL]">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>

<% while dr1.read() { %>
  <tr>
    <td> Ürün Adı :</td>
    <td> <%=dr1("urunadi");%> </td>
    <td> <%=dr1("urunlinki");%> </td>
  </tr>
<% } %>
</table>
    </div>
    </form>
</body>
</html>


---------------

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Text;
using System.Drawing;
using System.Data.Common;
using System.Data.OleDb;
namespace JOIN_PROJEM
{
    public partial class onurty : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
  
        OleDbConnection connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());


            string query = "select * from urunler";
            OleDbCommand dr1= new OleDbCommand(query, connection);
            dr1.ExecuteReader();
        }
    }
}

ı dont want grıdvıew repeater buıldıngstrıng literal and vs ı waNT WHILE datareader in web desıgner wıth vstutıo2015 ı dont want mvc project dr1 error explaın : dr1 does not exıst context what can i do
 
Last edited by a moderator:
Welcome to the forum.in the future please put code in code tags. Also, if you have two different issues with the same code base, it usually helps to fix one issue before moving on to the next issue. Now you have two threads in parallel. (I rejected your third thread which was the same code but you didn't go deeper into what help you needed.)
 
It looks like your dr1 is only declared with the scope of you Page_Load. If you want it to be available to your .ASPX, you'll need to declare it to be at the class level rather than the method level.

In C#, while statements have parenthesis. So:
C#:
while (some condition here is true)
Your line 14 should seems to be missing parenthesis around the dr1.read() call.

Also in C#, array indexing uses the [] operator. So:
C#:
arrayVariable[index]
Your lines 17 and 18 are using () instead of [].
 

Latest posts

Back
Top Bottom