• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

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

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
swtiley
Asked:
swtiley
  • 8
  • 7
  • 5
  • +1
2 Solutions
 
DhaestCommented:
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
 
chinu1310Commented:
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
 
DhaestCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
chinu1310Commented:
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
 
swtileyAuthor Commented:
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
 
chinu1310Commented:
String constr = "server=xxx;uid=sa;pwd=xxx;database=DatabaseName"

And exactly what is your error?
0
 
DhaestCommented:
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
 
chinu1310Commented:
I am sorry. Last post is not for you. Really sorry
0
 
swtileyAuthor Commented:
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
 
DhaestCommented:
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
 
swtileyAuthor Commented:
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
 
DhaestCommented:
Can you show the query you want to execute

(Dim cmd As sqldataadapter= new SqlDataAdapter(mmm, cnn)
--> what is mmm ?)
0
 
swtileyAuthor Commented:
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
 
DhaestCommented:
Try this:
adp.Fill(ds);
0
 
swtileyAuthor Commented:
Hi Dhaest - exactly the same error
0
 
DhaestCommented:
Is your 'DreamweaverCtrls.DataSet'  declared as public ?
(or how did you create this ?)
0
 
swtileyAuthor Commented:
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
 
renjurdevanCommented:
Are you in DreamweaverCTRLS namespace and which already have DataSet?
try declare System.Data.DataSet


Regards
Renju
0
 
DhaestCommented:
Did you try the suggestion of renjurdevan ?

Dim ds As System.Data.dataset = New System.Data.DataSet()
0
 
swtileyAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 7
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now