Showing posts with label sqldataadapter. Show all posts
Showing posts with label sqldataadapter. Show all posts

Friday, February 24, 2012

Accessing the sample database in Visual Basic .net sqlDataAdapter

I need some help with accessing the sample databases with
the SqlDataAdapter.
After double-clicking on SqlDataAdapter in Visual
Basic .net. I click on new connection and choose
Microsoft Ole DB Provider for SQL Server as the
provider. Then under the connection tab, I enter (local)
as the server name. And Choose Use Windows NT Inegrated
Security. Then under databases in the server, only
master, model, msdb, and tempdb show up. The sample
databases Northwind and pubs don't show up, as well as
the database which I created called Project.
In the SQL Server Enterprise Manager, under Console Root -
> Microsoft SQL Server -> SQL Server Group -> CR304216-
A\Project[WindowsNT] -> Databases
I see master, model, msdb, Northwind, Project, pubs, and
tempdb.
So, why don't I see Northwind, Project, and pubs in the
sqlDataAdapter console?Hi, Sabrina!
I'm fairly new to VB.net, but I'm working hard at learning it each day.
Anyway, have you tried using the "sa" user name (or better yet... just the u
ser name and password to one of the databases you have access to)? I tend t
o not use the Windows security and go with the user name and password provid
ed for SQL Server instead (
I seem to have problems getting connections the other way).
I would try that and see what happens.
Hope that helps.
Rick
-- Sabrina wrote: --
I need some help with accessing the sample databases with
the SqlDataAdapter.
After double-clicking on SqlDataAdapter in Visual
Basic .net. I click on new connection and choose
Microsoft Ole DB Provider for SQL Server as the
provider. Then under the connection tab, I enter (local)
as the server name. And Choose Use Windows NT Inegrated
Security. Then under databases in the server, only
master, model, msdb, and tempdb show up. The sample
databases Northwind and pubs don't show up, as well as
the database which I created called Project.
In the SQL Server Enterprise Manager, under Console Root -
> Microsoft SQL Server -> SQL Server Group -> CR304216-
A\Project[WindowsNT] -> Databases
I see master, model, msdb, Northwind, Project, pubs, and
tempdb.
So, why don't I see Northwind, Project, and pubs in the
sqlDataAdapter console?

Sunday, February 12, 2012

Accessing Queries in sqlDataAdapter

Hello Dears;

I have an SqlDataAdapter which contains may queries. One query contians 3 query parameters as follows:

SELECT SUM(Amount) AS Total
FROM Boxes
WHERE EntryDate BETWEEN @.date1 AND @.date2 ANDArea=@.Area

the query cannot be ran unless the queries parameters were provided. I have to access this query in code to add the parameters from controls. Is it possible to access it or use sqlDataSource instead?

Thanks alot

Here is one example I grabed from tutorial with a little modifications for your reference:

Sub GetAuthors_Click(SenderAs Object, EAs EventArgs)

Dim DSAs DataSet
Dim MyConnectionAs SqlConnection
Dim MyCommandAs SqlDataAdapter

Dim strSelectCommandAsString = "select * from Authors where state = @.State"

MyConnection =New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("PubString").ConnectionString
MyCommand =New SqlDataAdapter(strSelectCommand, MyConnection)

MyCommand.SelectCommand.Parameters.Add(New SqlParameter("@.State", SqlDbType.NVarChar, 2))
MyCommand.SelectCommand.Parameters("@.State").Value = someValue 'you need send in

DS =new DataSet()
MyCommand.Fill(DS, "Authors")

Mygv.DataSource=DS.Tables("Authors").DefaultView
Mygv.DataBind()
End Sub

You can add all your parameters to your SqlDataAdapter from your code.

|||Thanks Limno