Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Fala ai Pessoal, tudo bem ?To tentando aprender asp.net com c# e tentei fazer com que fosse retornado as informações da base Northwind que é padrão do Microsoft SQL Server.O erro que o visual studio imforma é que naImvalidOperationException was unhandled by user code.Invalid attempt to read when no data is present.se alguem puder me ajudar, ficarei agradecido.]ObrigadoSegue abaixo o código que estou usando----------------------------------------------------------------------------------------------------------------<%@ Page Language="C#" Debug="true" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Import Namespace= "System"%><%@ Import Namespace= "System.Data"%><%@ Import Namespace= "System.Data.SqlClient"%><html xmlns="[http://www.w3.org/1999/xhtml"](http://www.w3.org/1999/xhtml) ><head runat="server"> <title>Untitled Page</title></head><body><form id="Form1" name="form2" runat="server"><asp:Button ID="Button1" runat="server" Text="Button" OnClick="exibeRegistros" /></form><script language="C#" runat="Server"> public void exibeRegistros(Object sender, EventArgs e) { SqlConnection conn = new SqlConnection("server=localhost;uid=sa;pwd=;database=Northwind"); SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", conn); conn.Open(); SqlDataReader s = cmd.ExecuteReader(); Response.Write(s["CompanyName"].ToString()+ "<br/>"); s.Close(); conn.Close(); } </script></body></html>----------------------------------------------------------------------------------------------------------------Carregando comentários...