469,129 Members | 1,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,129 developers. It's quick & easy.

Error using ASP.NET C#

Hello,

I new on developing with ASP.NET and i wrote some lines of code. This
works fine when all the code is in one page, but when i split it up into and
ASPX file and make an DLL using a namespace i get an error :

============= ERROR
Compiler Error Message: CS0234: The type or namespace name 'SQLGetPhones'
does not exist in the class or namespace 'WallpaperEditorDataManager' (are
you missing an assembly reference?)

Source Error:

Line 12: public void fnFillFormData()
Line 13: {
Line 14: PhoneList.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select * from phones").DefaultView;
Line 15: PhoneList.DataBind();
Line 16:

Source File: E:\wwwroot\aspx\test1.aspx Line: 14
=========== / ERROR

I used the following command to compile the DLL:

csc /t:library /r:System.dll /r:System.Data.dll
/out:bin/WallpaperEditorDataManager.dll test1.cs
Could someone explain me what is going wrong? I also,below, added the lines
of code i use.

Please help me with my first steps.

Bart de Vries

=========== SOURCE test1.cs
using System;
using System.Data;
using System.Data.SqlClient;
namespace WallpaperEditorDataManager
{
public class PhonesDB
{
public DataTable SQLGetPhones(string strQuery)
{

SqlConnection myConnection = new SqlConnection("User
ID=xxxx;password=xxxx;Initial Catalog=xxxx;Data Source=localhost;");
SqlDataAdapter myAdapter = new SqlDataAdapter(strQuery,
myConnection);
DataSet phones = new DataSet();
myAdapter.Fill(phones,"phones");

return phones.Tables[0];
}
}
}

========== / SOURCE test1.cs
========== SOURCE test1.aspx

<%@ Page Language="c#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="WallpaperEditorDataManager" %>
<script runat="server">

void Page_Load(Object s, EventArgs e)
{
fnFillFormData();
}

public void fnFillFormData()
{
PhoneList.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select * from phones").DefaultView;
PhoneList.DataBind();
ddlPhoneBrand.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select DISTINCT phone_brand from
phones").DefaultView;
ddlPhoneBrand.DataTextField = "phone_brand";
ddlPhoneBrand.DataValueField = "phone_brand";
ddlPhoneBrand.DataBind();
}

</script>
blah blah blah, some more lines containing the HTML and
ASP data elements

========== / SOURCE test1.aspx
Nov 16 '05 #1
4 1463
Or should i use codeBehind instead?
"Bart de Vries" <ma**@notpossible.nl> schreef in bericht
news:40***********************@news.xs4all.nl...
Hello,

I new on developing with ASP.NET and i wrote some lines of code. This
works fine when all the code is in one page, but when i split it up into and ASPX file and make an DLL using a namespace i get an error :

============= ERROR
Compiler Error Message: CS0234: The type or namespace name 'SQLGetPhones'
does not exist in the class or namespace 'WallpaperEditorDataManager' (are
you missing an assembly reference?)

Source Error:

Line 12: public void fnFillFormData()
Line 13: {
Line 14: PhoneList.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select * from phones").DefaultView; Line 15: PhoneList.DataBind();
Line 16:

Source File: E:\wwwroot\aspx\test1.aspx Line: 14
=========== / ERROR

I used the following command to compile the DLL:

csc /t:library /r:System.dll /r:System.Data.dll
/out:bin/WallpaperEditorDataManager.dll test1.cs
Could someone explain me what is going wrong? I also,below, added the lines of code i use.

Please help me with my first steps.

Bart de Vries

=========== SOURCE test1.cs
using System;
using System.Data;
using System.Data.SqlClient;
namespace WallpaperEditorDataManager
{
public class PhonesDB
{
public DataTable SQLGetPhones(string strQuery)
{

SqlConnection myConnection = new SqlConnection("User
ID=xxxx;password=xxxx;Initial Catalog=xxxx;Data Source=localhost;");
SqlDataAdapter myAdapter = new SqlDataAdapter(strQuery,
myConnection);
DataSet phones = new DataSet();
myAdapter.Fill(phones,"phones");

return phones.Tables[0];
}
}
}

========== / SOURCE test1.cs
========== SOURCE test1.aspx

<%@ Page Language="c#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="WallpaperEditorDataManager" %>
<script runat="server">

void Page_Load(Object s, EventArgs e)
{
fnFillFormData();
}

public void fnFillFormData()
{
PhoneList.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select * from phones").DefaultView; PhoneList.DataBind();
ddlPhoneBrand.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select DISTINCT phone_brand from
phones").DefaultView;
ddlPhoneBrand.DataTextField = "phone_brand";
ddlPhoneBrand.DataValueField = "phone_brand";
ddlPhoneBrand.DataBind();
}

</script>
blah blah blah, some more lines containing the HTML and
ASP data elements

========== / SOURCE test1.aspx

Nov 16 '05 #2
Hi,
Or should i use codeBehind instead?


Yes, you should
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 16 '05 #3
is there a specific reason for using Codebehind instead of the other way?
And could you also still tell me why the first option is going wrong?

Bart de Vries
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
schreef in bericht news:uu****************@TK2MSFTNGP09.phx.gbl...
Hi,
Or should i use codeBehind instead?


Yes, you should
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nov 16 '05 #4
Bart,

You are trying to call an instance method (SQLGetPhones), which belongs
to the class PhonesDB, directly from the namespace. That is not possible.

two solutions:
a) first an instance of PhonesDb, then call the method
PhonesDB myDB = new PhonesDB();
PhoneList.DataSource = myDB.SQLGetPhones(...);

b) make it a static method and call that
add "static" to the declaration:
public static DataTable SQLGetPhones(string strQuery)
PhoneList.DataSource = PhonesDB.SQLGetPhones(...)

Hans Kesting

"Bart de Vries" <ma**@notpossible.nl> wrote in message news:40***********************@news.xs4all.nl...
Hello,

I new on developing with ASP.NET and i wrote some lines of code. This
works fine when all the code is in one page, but when i split it up into and
ASPX file and make an DLL using a namespace i get an error :

============= ERROR
Compiler Error Message: CS0234: The type or namespace name 'SQLGetPhones'
does not exist in the class or namespace 'WallpaperEditorDataManager' (are
you missing an assembly reference?)

Source Error:

Line 12: public void fnFillFormData()
Line 13: {
Line 14: PhoneList.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select * from phones").DefaultView;
Line 15: PhoneList.DataBind();
Line 16:

Source File: E:\wwwroot\aspx\test1.aspx Line: 14
=========== / ERROR

I used the following command to compile the DLL:

csc /t:library /r:System.dll /r:System.Data.dll
/out:bin/WallpaperEditorDataManager.dll test1.cs
Could someone explain me what is going wrong? I also,below, added the lines
of code i use.

Please help me with my first steps.

Bart de Vries

=========== SOURCE test1.cs
using System;
using System.Data;
using System.Data.SqlClient;
namespace WallpaperEditorDataManager
{
public class PhonesDB
{
public DataTable SQLGetPhones(string strQuery)
{

SqlConnection myConnection = new SqlConnection("User
ID=xxxx;password=xxxx;Initial Catalog=xxxx;Data Source=localhost;");
SqlDataAdapter myAdapter = new SqlDataAdapter(strQuery,
myConnection);
DataSet phones = new DataSet();
myAdapter.Fill(phones,"phones");

return phones.Tables[0];
}
}
}

========== / SOURCE test1.cs
========== SOURCE test1.aspx

<%@ Page Language="c#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="WallpaperEditorDataManager" %>
<script runat="server">

void Page_Load(Object s, EventArgs e)
{
fnFillFormData();
}

public void fnFillFormData()
{
PhoneList.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select * from phones").DefaultView;
PhoneList.DataBind();
ddlPhoneBrand.DataSource =
WallpaperEditorDataManager.SQLGetPhones("Select DISTINCT phone_brand from
phones").DefaultView;
ddlPhoneBrand.DataTextField = "phone_brand";
ddlPhoneBrand.DataValueField = "phone_brand";
ddlPhoneBrand.DataBind();
}

</script>
blah blah blah, some more lines containing the HTML and
ASP data elements

========== / SOURCE test1.aspx

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
5 posts views Thread by Enos Meroka | last post: by
6 posts views Thread by Peter Frost | last post: by
9 posts views Thread by JTrigger | last post: by
4 posts views Thread by james margey | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.