Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: DataGrid and SQL in asp+


Message #1 by Simon.Willcock@i... on Thu, 3 Aug 2000 09:23:20 +0100
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01BFFD25.AFDAAF28

Content-Type: text/plain;

	charset="iso-8859-1"



Hi - has anybody any idea why the following ASP+ fragment from the MSDN mag

given out at the PDC  (page 28) -  returns "BC30311:Cannot convert

expression from integer to ICollection" its pointing at the line in the code

below  "DataGrid1.DataSource = myCommand.Execute", I cannot find any

examples of SQL commands being used (other than in the MSDN mag). All I'm

trying to do is to bind some data from a SQL 2000 database to the DataGrid

control to display it, ASP+ SQL commands (rather than ADO) look much easier

to understand/maintain hence my determination to get the example to work. 

 

Thanks

Simon

 

 

<%@ Page EnableSessionState="False" MaintainState="false" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SQL" %>



<script language="VB" runat="server">

 

 Sub Page_Load(sender as Object, e As EventArgs)

  Dim myCommand As SQLCommand

  Dim SQL as String

  Dim ConnStr as String

  

  SQL = "select * from item"

  ConnStr = "Server=localhost; Database=eShop;uid=sa;pwd="

   

  myCommand = New SQLCommand(SQL, ConnStr)

      

  DataGrid1.DataSource = myCommand.Execute

  DataGrid1.DataBind

 End Sub

 </script>

 

 

<HTML><HEAD>

  <meta name="GENERATOR" content="Microsoft Visual Studio 7.0">

  <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"></HEAD>

 

  <body>

     <form id="WebForm1" method="post" runat="server">

        <asp:DataGrid id="DataGrid1" Runat="server" />

        <p>This is a test app</p>Name : <asp:TextBox id=Name

runat="SERVER"></asp:TextBox>

     </form>

  </body></html>



 

 




Message #2 by "Dave Sussman" <davids@i...> on Tue, 8 Aug 2000 08:43:29 +0100
This is a multi-part message in MIME format.



------=_NextPart_000_0028_01C00114.B9DC9A70

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



Simon



Unfortunately this method of databinding didn't completed in time to 

make the PDC release. The article was written some time before the 

cut-off date for code. It's hopedthat this form of databinding will be 

available from Beta 1.



In the meantime you'll need to use the code shown in the book (page 92). 

You can download it from http://www.wrox.com/beta.



Dave

  <Simon.Willcock@i...> wrote in message news:8354@a...

  Hi - has anybody any idea why the following ASP+ fragment from the 

MSDN mag given out at the PDC  (page 28) -  returns "BC30311:Cannot 

convert expression from integer to ICollection" its pointing at the line 

in the code below  "DataGrid1.DataSource =3D myCommand.Execute", I 

cannot find any examples of SQL commands being used (other than in the 

MSDN mag). All I'm trying to do is to bind some data from a SQL 2000 

database to the DataGrid control to display it, ASP+ SQL commands 

(rather than ADO) look much easier to understand/maintain hence my 

determination to get the example to work.

  

  Thanks

  Simon

  

  

  <%@ Page EnableSessionState=3D"False" MaintainState=3D"false" %>

  <%@ Import Namespace=3D"System.Data" %>

  <%@ Import Namespace=3D"System.Data.SQL" %>



  <script language=3D"VB" runat=3D"server">

  

   Sub Page_Load(sender as Object, e As EventArgs)

    Dim myCommand As SQLCommand

    Dim SQL as String

    Dim ConnStr as String

   

    SQL =3D "select * from item"

    ConnStr =3D "Server=3Dlocalhost; Database=3DeShop;uid=3Dsa;pwd=3D"

    

    myCommand =3D New SQLCommand(SQL, ConnStr)

       

    DataGrid1.DataSource =3D myCommand.Execute

    DataGrid1.DataBind

   End Sub

   </script>

  

  

  <HTML><HEAD>

    <meta name=3D"GENERATOR" content=3D"Microsoft Visual Studio 7.0">

    <meta name=3D"CODE_LANGUAGE" content=3D"Visual Basic 7.0"></HEAD>

  

    <body>

       <form id=3D"WebForm1" method=3D"post" runat=3D"server">

          <asp:DataGrid id=3D"DataGrid1" Runat=3D"server" />

          <p>This is a test app</p>Name : <asp:TextBox id=3DName 

runat=3D"SERVER"></asp:TextBox>

       </form>

    </body></html>













  Return to Index