Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2007, 11:57 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default mobile control sql access

Hi ,

im very new to c# and am having a very difficult time of it trying to connect a mobile form to a sql database.

when I enter the following code

***********************************

<script runat="server">
    string strConn = "Data Source=DANEEL;Initial Catalog=newpubstest;User ID=newstudentmm;Password=studentmm providerName=System.Data.SqlClient";
    SqlConnection myConnection = new SqlConnection(strConn);
    //create connection string

    //create connection query
    string strSql = "SELECT * FROM authors";
    //create db connection object
 </script>
****************************************

I get this error about by connection object and string

>>Error 1 A field initializer cannot reference the nonstatic field, method, or property 'ASP.default_aspx.strConn' \\sideshowbob1\students\S02090619\My Documents\Visual Studio 2005\WebSites\mobile\mobile_location\Default.aspx 8 52 \\sideshowbob1\students\...\mobile_location
Id really appreciate if somebody could explain this error to me and maybe tell me what Im doing wrong.

Thanks A lot

 
Old March 22nd, 2007, 01:44 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

According to http://msdn2.microsoft.com/en-us/library/5724t6za(vs.80).aspx...

<article segment>
Visual C# Reference: Errors and Warnings
Compiler Error CS0236
Error Message
A field initializer cannot reference the nonstatic field, method, or property 'field'

Instance fields cannot be used to initialize other instance fields outside of a method. If you are attempting to initialize a variable outside of a method, consider performing the initialization inside the class constructor. For more information, see Methods (C# Programming Guide).
</article segment>

Try this...
<script runat="server">
public void main()
{
    string strConn = "Data Source=DANEEL;Initial Catalog=newpubstest;User ID=newstudentmm;Password=studentmm providerName=System.Data.SqlClient";
    System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(strConn);
    //create connection string

    //create connection query
    string strSql = "SELECT * FROM authors";
    //create db connection object
}
</script>


Adam Gossage
Lake Wylie, SC, USA
 
Old March 22nd, 2007, 01:45 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

FYI... C# questions need to go to [P2P Forum]\[C# C++]

Adam Gossage
Lake Wylie, SC, USA





Similar Threads
Thread Thread Starter Forum Replies Last Post
Mobile Control in System.Web.UI.Page hpfarstad ASP.NET 2.0 Professional 0 August 28th, 2006 05:00 AM
SQL Server Mobile 5 issue in VS.NET rodmcleay Visual Studio 2005 0 July 10th, 2006 11:49 PM
Layout of Mobile Control rehmanmansoor C# 2005 0 December 9th, 2005 06:59 AM
Converting an Access VBA application to Mobile PDA Paulsh Access VBA 0 September 21st, 2004 07:27 AM
urgent: <mobile:call> control is being unfriendly kawak_zx7 General .NET 0 August 26th, 2004 11:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.