Home All Groups Group Topic Archive Search About

ADO.NET 2.0 - Simple question for you...

Author
17 Aug 2006 6:07 PM
VB Programmer
I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET 2.0
(VB.NET) that does the following:

1. Opens up a connection to my SqlExpress db.  (The connectionstring is in
the <connectionStrings> section of my web.config)
2. Runs a query, storing results in a datatable.
3. Closes connection

Can anyone assist?

Thanks!

Author
17 Aug 2006 7:36 PM
zacks
VB Programmer wrote:
> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET 2.0
> (VB.NET) that does the following:
>
> 1. Opens up a connection to my SqlExpress db.  (The connectionstring is in
> the <connectionStrings> section of my web.config)
> 2. Runs a query, storing results in a datatable.
> 3. Closes connection
>
> Can anyone assist?
>
> Thanks!

Not sure about ASP.NET and SQL Express, but this works for me in VB.NET
and SQL Server:

        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim myDataAdapter As SqlDataAdapter
        Dim myDataSet As New DataSet
        Dim myDataTable As DataTable

        myConnection = New SqlConnection("Data
Source=(local);Database=master;Integrated Security=true;")
        myConnection.Open()
        myCommand = New SqlCommand("Select blah blah", myConnection)
        myDataAdapter = New SqlDataAdapter()
        myDataAdapter.SelectCommand = myCommand
        myDataAdapter.Fill(myDataSet, "MyTableName")
        myDataTable = myDataSet.Tables.Item("MyTableName")
        myConnection.Close()
        Console.WriteLine("Press any key to continue.")
        Console.ReadKey()
Author
17 Aug 2006 7:56 PM
Marina Levit [MVP]
I don't think he/she is having a problem doing it, I think they want to get
the code to do it.

Looks suspiciously like a homework assignment...  Not that it should be
difficult to find an example of this online, but whoever this is, seems to
be too lazy to even do a Google search...

<za***@construction-imaging.com> wrote in message
Show quote
news:1155843406.305661.284360@b28g2000cwb.googlegroups.com...
>
> VB Programmer wrote:
>> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET 2.0
>> (VB.NET) that does the following:
>>
>> 1. Opens up a connection to my SqlExpress db.  (The connectionstring is
>> in
>> the <connectionStrings> section of my web.config)
>> 2. Runs a query, storing results in a datatable.
>> 3. Closes connection
>>
>> Can anyone assist?
>>
>> Thanks!
>
> Not sure about ASP.NET and SQL Express, but this works for me in VB.NET
> and SQL Server:
>
>        Dim myConnection As SqlConnection
>        Dim myCommand As SqlCommand
>        Dim myDataAdapter As SqlDataAdapter
>        Dim myDataSet As New DataSet
>        Dim myDataTable As DataTable
>
>        myConnection = New SqlConnection("Data
> Source=(local);Database=master;Integrated Security=true;")
>        myConnection.Open()
>        myCommand = New SqlCommand("Select blah blah", myConnection)
>        myDataAdapter = New SqlDataAdapter()
>        myDataAdapter.SelectCommand = myCommand
>        myDataAdapter.Fill(myDataSet, "MyTableName")
>        myDataTable = myDataSet.Tables.Item("MyTableName")
>        myConnection.Close()
>        Console.WriteLine("Press any key to continue.")
>        Console.ReadKey()
>
Author
17 Aug 2006 8:19 PM
VB Programmer
Thanks Marina, but I'm over 30.  Not a homework assignment.  :)

I tried Google but apparently wasn't searching for the right stuff...

Show quote
"Marina Levit [MVP]" <someone@nospam.com> wrote in message
news:%23xQN8cjwGHA.1484@TK2MSFTNGP04.phx.gbl...
>I don't think he/she is having a problem doing it, I think they want to get
>the code to do it.
>
> Looks suspiciously like a homework assignment...  Not that it should be
> difficult to find an example of this online, but whoever this is, seems to
> be too lazy to even do a Google search...
>
> <za***@construction-imaging.com> wrote in message
> news:1155843406.305661.284360@b28g2000cwb.googlegroups.com...
>>
>> VB Programmer wrote:
>>> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET
>>> 2.0
>>> (VB.NET) that does the following:
>>>
>>> 1. Opens up a connection to my SqlExpress db.  (The connectionstring is
>>> in
>>> the <connectionStrings> section of my web.config)
>>> 2. Runs a query, storing results in a datatable.
>>> 3. Closes connection
>>>
>>> Can anyone assist?
>>>
>>> Thanks!
>>
>> Not sure about ASP.NET and SQL Express, but this works for me in VB.NET
>> and SQL Server:
>>
>>        Dim myConnection As SqlConnection
>>        Dim myCommand As SqlCommand
>>        Dim myDataAdapter As SqlDataAdapter
>>        Dim myDataSet As New DataSet
>>        Dim myDataTable As DataTable
>>
>>        myConnection = New SqlConnection("Data
>> Source=(local);Database=master;Integrated Security=true;")
>>        myConnection.Open()
>>        myCommand = New SqlCommand("Select blah blah", myConnection)
>>        myDataAdapter = New SqlDataAdapter()
>>        myDataAdapter.SelectCommand = myCommand
>>        myDataAdapter.Fill(myDataSet, "MyTableName")
>>        myDataTable = myDataSet.Tables.Item("MyTableName")
>>        myConnection.Close()
>>        Console.WriteLine("Press any key to continue.")
>>        Console.ReadKey()
>>
>
>
Author
18 Aug 2006 5:25 AM
Cor Ligthert [MVP]
VB Programmer,

Strange 2 messages before you somebody has asked almost the same question
and got more answers on that including mine with a piece of sample code.

Cor

Show quote
"VB Programmer" <donotemai***@somewhere.com> schreef in bericht
news:uq31mpjwGHA.1484@TK2MSFTNGP04.phx.gbl...
> Thanks Marina, but I'm over 30.  Not a homework assignment.  :)
>
> I tried Google but apparently wasn't searching for the right stuff...
>
> "Marina Levit [MVP]" <someone@nospam.com> wrote in message
> news:%23xQN8cjwGHA.1484@TK2MSFTNGP04.phx.gbl...
>>I don't think he/she is having a problem doing it, I think they want to
>>get the code to do it.
>>
>> Looks suspiciously like a homework assignment...  Not that it should be
>> difficult to find an example of this online, but whoever this is, seems
>> to be too lazy to even do a Google search...
>>
>> <za***@construction-imaging.com> wrote in message
>> news:1155843406.305661.284360@b28g2000cwb.googlegroups.com...
>>>
>>> VB Programmer wrote:
>>>> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET
>>>> 2.0
>>>> (VB.NET) that does the following:
>>>>
>>>> 1. Opens up a connection to my SqlExpress db.  (The connectionstring is
>>>> in
>>>> the <connectionStrings> section of my web.config)
>>>> 2. Runs a query, storing results in a datatable.
>>>> 3. Closes connection
>>>>
>>>> Can anyone assist?
>>>>
>>>> Thanks!
>>>
>>> Not sure about ASP.NET and SQL Express, but this works for me in VB.NET
>>> and SQL Server:
>>>
>>>        Dim myConnection As SqlConnection
>>>        Dim myCommand As SqlCommand
>>>        Dim myDataAdapter As SqlDataAdapter
>>>        Dim myDataSet As New DataSet
>>>        Dim myDataTable As DataTable
>>>
>>>        myConnection = New SqlConnection("Data
>>> Source=(local);Database=master;Integrated Security=true;")
>>>        myConnection.Open()
>>>        myCommand = New SqlCommand("Select blah blah", myConnection)
>>>        myDataAdapter = New SqlDataAdapter()
>>>        myDataAdapter.SelectCommand = myCommand
>>>        myDataAdapter.Fill(myDataSet, "MyTableName")
>>>        myDataTable = myDataSet.Tables.Item("MyTableName")
>>>        myConnection.Close()
>>>        Console.WriteLine("Press any key to continue.")
>>>        Console.ReadKey()
>>>
>>
>>
>
>
Author
18 Aug 2006 11:05 AM
VB Programmer
I don't think that was me Cor.

Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:O6kxGaowGHA.4160@TK2MSFTNGP06.phx.gbl...
> VB Programmer,
>
> Strange 2 messages before you somebody has asked almost the same question
> and got more answers on that including mine with a piece of sample code.
>
> Cor
>
> "VB Programmer" <donotemai***@somewhere.com> schreef in bericht
> news:uq31mpjwGHA.1484@TK2MSFTNGP04.phx.gbl...
>> Thanks Marina, but I'm over 30.  Not a homework assignment.  :)
>>
>> I tried Google but apparently wasn't searching for the right stuff...
>>
>> "Marina Levit [MVP]" <someone@nospam.com> wrote in message
>> news:%23xQN8cjwGHA.1484@TK2MSFTNGP04.phx.gbl...
>>>I don't think he/she is having a problem doing it, I think they want to
>>>get the code to do it.
>>>
>>> Looks suspiciously like a homework assignment...  Not that it should be
>>> difficult to find an example of this online, but whoever this is, seems
>>> to be too lazy to even do a Google search...
>>>
>>> <za***@construction-imaging.com> wrote in message
>>> news:1155843406.305661.284360@b28g2000cwb.googlegroups.com...
>>>>
>>>> VB Programmer wrote:
>>>>> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET
>>>>> 2.0
>>>>> (VB.NET) that does the following:
>>>>>
>>>>> 1. Opens up a connection to my SqlExpress db.  (The connectionstring
>>>>> is in
>>>>> the <connectionStrings> section of my web.config)
>>>>> 2. Runs a query, storing results in a datatable.
>>>>> 3. Closes connection
>>>>>
>>>>> Can anyone assist?
>>>>>
>>>>> Thanks!
>>>>
>>>> Not sure about ASP.NET and SQL Express, but this works for me in VB.NET
>>>> and SQL Server:
>>>>
>>>>        Dim myConnection As SqlConnection
>>>>        Dim myCommand As SqlCommand
>>>>        Dim myDataAdapter As SqlDataAdapter
>>>>        Dim myDataSet As New DataSet
>>>>        Dim myDataTable As DataTable
>>>>
>>>>        myConnection = New SqlConnection("Data
>>>> Source=(local);Database=master;Integrated Security=true;")
>>>>        myConnection.Open()
>>>>        myCommand = New SqlCommand("Select blah blah", myConnection)
>>>>        myDataAdapter = New SqlDataAdapter()
>>>>        myDataAdapter.SelectCommand = myCommand
>>>>        myDataAdapter.Fill(myDataSet, "MyTableName")
>>>>        myDataTable = myDataSet.Tables.Item("MyTableName")
>>>>        myConnection.Close()
>>>>        Console.WriteLine("Press any key to continue.")
>>>>        Console.ReadKey()
>>>>
>>>
>>>
>>
>>
>
>
Author
18 Aug 2006 11:12 AM
Cor Ligthert [MVP]
No but you said that you had searched,

>>> I tried Google but apparently wasn't searching for the right stuff...

http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/browse_frm/thread/9ce3753ccee58e1c/1861f39319def310?#1861f39319def310

Did you look at that message?

Cor

Show quote
"VB Programmer" <donotemai***@somewhere.com> schreef in bericht
news:%2341KyYrwGHA.1288@TK2MSFTNGP02.phx.gbl...
>I don't think that was me Cor.
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:O6kxGaowGHA.4160@TK2MSFTNGP06.phx.gbl...
>> VB Programmer,
>>
>> Strange 2 messages before you somebody has asked almost the same question
>> and got more answers on that including mine with a piece of sample code.
>>
>> Cor
>>
>> "VB Programmer" <donotemai***@somewhere.com> schreef in bericht
>> news:uq31mpjwGHA.1484@TK2MSFTNGP04.phx.gbl...
>>> Thanks Marina, but I'm over 30.  Not a homework assignment.  :)
>>>
>>> I tried Google but apparently wasn't searching for the right stuff...
>>>
>>> "Marina Levit [MVP]" <someone@nospam.com> wrote in message
>>> news:%23xQN8cjwGHA.1484@TK2MSFTNGP04.phx.gbl...
>>>>I don't think he/she is having a problem doing it, I think they want to
>>>>get the code to do it.
>>>>
>>>> Looks suspiciously like a homework assignment...  Not that it should be
>>>> difficult to find an example of this online, but whoever this is, seems
>>>> to be too lazy to even do a Google search...
>>>>
>>>> <za***@construction-imaging.com> wrote in message
>>>> news:1155843406.305661.284360@b28g2000cwb.googlegroups.com...
>>>>>
>>>>> VB Programmer wrote:
>>>>>> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET
>>>>>> 2.0
>>>>>> (VB.NET) that does the following:
>>>>>>
>>>>>> 1. Opens up a connection to my SqlExpress db.  (The connectionstring
>>>>>> is in
>>>>>> the <connectionStrings> section of my web.config)
>>>>>> 2. Runs a query, storing results in a datatable.
>>>>>> 3. Closes connection
>>>>>>
>>>>>> Can anyone assist?
>>>>>>
>>>>>> Thanks!
>>>>>
>>>>> Not sure about ASP.NET and SQL Express, but this works for me in
>>>>> VB.NET
>>>>> and SQL Server:
>>>>>
>>>>>        Dim myConnection As SqlConnection
>>>>>        Dim myCommand As SqlCommand
>>>>>        Dim myDataAdapter As SqlDataAdapter
>>>>>        Dim myDataSet As New DataSet
>>>>>        Dim myDataTable As DataTable
>>>>>
>>>>>        myConnection = New SqlConnection("Data
>>>>> Source=(local);Database=master;Integrated Security=true;")
>>>>>        myConnection.Open()
>>>>>        myCommand = New SqlCommand("Select blah blah", myConnection)
>>>>>        myDataAdapter = New SqlDataAdapter()
>>>>>        myDataAdapter.SelectCommand = myCommand
>>>>>        myDataAdapter.Fill(myDataSet, "MyTableName")
>>>>>        myDataTable = myDataSet.Tables.Item("MyTableName")
>>>>>        myConnection.Close()
>>>>>        Console.WriteLine("Press any key to continue.")
>>>>>        Console.ReadKey()
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
17 Aug 2006 8:19 PM
VB Programmer
Thanks.  I will give it a try zacks.

<za***@construction-imaging.com> wrote in message
Show quote
news:1155843406.305661.284360@b28g2000cwb.googlegroups.com...
>
> VB Programmer wrote:
>> I have an ASP.NET 2.0 website.  I want to write a function in ADO.NET 2.0
>> (VB.NET) that does the following:
>>
>> 1. Opens up a connection to my SqlExpress db.  (The connectionstring is
>> in
>> the <connectionStrings> section of my web.config)
>> 2. Runs a query, storing results in a datatable.
>> 3. Closes connection
>>
>> Can anyone assist?
>>
>> Thanks!
>
> Not sure about ASP.NET and SQL Express, but this works for me in VB.NET
> and SQL Server:
>
>        Dim myConnection As SqlConnection
>        Dim myCommand As SqlCommand
>        Dim myDataAdapter As SqlDataAdapter
>        Dim myDataSet As New DataSet
>        Dim myDataTable As DataTable
>
>        myConnection = New SqlConnection("Data
> Source=(local);Database=master;Integrated Security=true;")
>        myConnection.Open()
>        myCommand = New SqlCommand("Select blah blah", myConnection)
>        myDataAdapter = New SqlDataAdapter()
>        myDataAdapter.SelectCommand = myCommand
>        myDataAdapter.Fill(myDataSet, "MyTableName")
>        myDataTable = myDataSet.Tables.Item("MyTableName")
>        myConnection.Close()
>        Console.WriteLine("Press any key to continue.")
>        Console.ReadKey()
>

AddThis Social Bookmark Button