?
Solved

ASP.NET (VB.NET) Database connection - How to FILL a Dataset

Posted on 2007-07-25
21
Medium Priority
?
493 Views
Last Modified: 2013-11-07
Hi I am very new to ASP programming, and am having problems around database connections, I have inherited aweb-site designed and maintained in Dreamweaver (which is adding to my frustrations) with the code I have being :

<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.system.data" %>
<%@ Import Namespace="System.Data.SQLClient" %>

<script runat="server">
Sub Page_Load(Src As Object, E As EventArgs)

dim constr  as string = "Persist Security Info=False;Data Source=swt005;Initial Catalog=opappslive;User ID=xxxxxx;Password=xxxxxx;"

Dim cmd As sqldataadapter= new SqlDataAdapter(mmm, cnn)
Dim ds As dataset = New DataSet()
cmd.Fill(ds,"Details")
.....
--------------

the error I am getting is
"Overload resolution failed because no accessible 'Fill' can be called with these arguments"
with the cmd.fill line in the example above being highlighted.

Does anybody have any ideas where I am going wrong, and if so what do I need to do to resolve.

Thanks
...Steve
0
Comment
Question by:swtiley
  • 8
  • 7
  • 5
  • +1
21 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 19563281
Dim cmd As New SqlCommand
cmd.Connection = cn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select * from yourtable"

Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmd)

Dim ds As DataSet = New DataSet
adapter.Fill(ds, "myTable")
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19563344
Make this as a function in your class file

public static DataSet test(string constr,string query)
        {
            String query = query;
            SqlConnection conn = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand(query, conn);            
            SqlDataAdapter adp = new SqlDataAdapter(query, constr);
            conn.Open();            
            DataSet ds = new DataSet();
            adp.Fill(ds, "Post");
            conn.Close();
            return ds;
        }

Just pass query and connection string
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 1000 total points
ID: 19563354
To chinu1310.
I guess there is one mistake of your syntax
 SqlDataAdapter adp = new SqlDataAdapter(query, constr);
must be
 SqlDataAdapter adp = new SqlDataAdapter(cmd);
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 14

Assisted Solution

by:chinu1310
chinu1310 earned 1000 total points
ID: 19563364
Ohh I am sorry boss.

Infact we don't need that line at all.
I forgot to comment it Thanks for pointing.

Here you go.

 public static DataSet test(string constr)
        {
            String query = "Select* from Test";
            SqlConnection conn = new SqlConnection(constr);
                   
            SqlDataAdapter adp = new SqlDataAdapter(query, constr);
            conn.Open();            
            DataSet ds = new DataSet();
            adp.Fill(ds, "Post");
            conn.Close();
            return ds;
        }
0
 
LVL 1

Author Comment

by:swtiley
ID: 19563458
Hi guys and thanks for your comments - but I am still getting exactly the same error - is it possibly the database connection string that is at fault ? (please note I am having to convert to asp / vb.net.

I will put into a class file later I just want to get it working first (thanks for the pointer though)

-------
dim query as string = "Select * from store_details"
dim constr  as string = "Persist Security Info=False;Data Source=swt005;Initial Catalog=opappslive;User ID=XXXXX;Password=XXXXX;"
dim conn as SqlConnection = new SqlConnection(constr)
dim cmd as SqlCommand = new SqlCommand(query, conn)          
dim  adp as SqlDataAdapter = new SqlDataAdapter(cmd)
                  
conn.Open()
dim ds as DataSet = new DataSet()
adp.Fill(ds, "Post")
conn.Close()
return ds;
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19563473
String constr = "server=xxx;uid=sa;pwd=xxx;database=DatabaseName"

And exactly what is your error?
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19563484
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19563488
To what database are you connecting ? Are you sure that the user/password is correct ?

For the connectionstring, take a loot at http://www.connectionstrings.com/
0
 
LVL 14

Expert Comment

by:chinu1310
ID: 19563490
I am sorry. Last post is not for you. Really sorry
0
 
LVL 1

Author Comment

by:swtiley
ID: 19563552
Hi Chinu1310
the error I am getting is

--------Compiler Error Message: BC30518:
Overload resolution failed because no accessible 'Fill' can be called with these arguments:

Source Error:
Line 120:            conn.Open()
Line 121:            dim ds as DataSet = new DataSet()
Line 122:            adp.Fill(ds, "Post") ------------------- ("this line is highlighted)
Line 123:            conn.Close()
Line 124: '           return ds;
 
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19563595
Can you add an errorhandler and give us some more information about the error that you catch then.

public static DataSet test(string constr)
        {
       try
        {
                   String query = "Select* from Test";
                   SqlConnection conn = new SqlConnection(constr);
                   
                   SqlDataAdapter adp = new SqlDataAdapter(query, constr);
                   conn.Open();            
                   DataSet ds = new DataSet();
                   adp.Fill(ds, "Post");
                   conn.Close();
                   return ds;
            }
            catch (Exception ex)
            {
                throw ex;  --> break on this line
            }
}
0
 
LVL 1

Author Comment

by:swtiley
ID: 19563700
I hope this means something to you DHaest (as it means very little to me :-)

c:\inetpub\wwwroot\Appointments\ApptOverview.aspx(124) : error BC30518: Overload resolution failed because no accessible 'Fill' can be called with these arguments:
    'Public Function Fill(startRecord As Integer, maxRecords As Integer, ParamArray dataTables() As System.Data.DataTable) As Integer': Value of type 'DreamweaverCtrls.DataSet' cannot be converted to 'Integer'.
    'Public Function Fill(dataSet As System.Data.DataSet, srcTable As String) As Integer': Value of type 'DreamweaverCtrls.DataSet' cannot be converted to 'System.Data.DataSet'.

Cheers for the continued help
Steve
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19563727
Can you show the query you want to execute

(Dim cmd As sqldataadapter= new SqlDataAdapter(mmm, cnn)
--> what is mmm ?)
0
 
LVL 1

Author Comment

by:swtiley
ID: 19563768
Hi Dhaest,

MMM  was a very simple "select * from tablename" query - this has got me completely stumped as I have taken code from a VS2005 project which works correctly, but for whatever reason it will not work within the dreamweaver environment!
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19563798
Try this:
adp.Fill(ds);
0
 
LVL 1

Author Comment

by:swtiley
ID: 19563819
Hi Dhaest - exactly the same error
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19563876
Is your 'DreamweaverCtrls.DataSet'  declared as public ?
(or how did you create this ?)
0
 
LVL 1

Author Comment

by:swtiley
ID: 19563961
To be honest Dhaest, I would not even know where the DreamweaverCTRLS.dataset is declared, I certainly have not explicity done so myself. There is a Dreamweacerctrls.dll in a bin directory off the root of the web-site.

0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 19564208
Are you in DreamweaverCTRLS namespace and which already have DataSet?
try declare System.Data.DataSet


Regards
Renju
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 19572043
Did you try the suggestion of renjurdevan ?

Dim ds As System.Data.dataset = New System.Data.DataSet()
0
 
LVL 1

Author Comment

by:swtiley
ID: 19584276
Thanks for all your comments guys. still does not work, and have come to the conclusion that Dreamweaver really is not up to the job for much else other than CSS styling and design.

Have worked around the problem using other functionality.

But to anybody else reading this thread I would definitely recommend utilising any other product for interactive web-sites such as VS2005 rather than Dreamweaver.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question