Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Can anyone tell me why this does not work?

Reply
 
Old 07-21-2008   #1 (permalink)
bill


 
 

Can anyone tell me why this does not work?

You've got it declared twice.


"bill" <bill@xxxxxx> wrote in message
news:Oq0CQT56IHA.4864@xxxxxx
Quote:

> Thank you! You've pretty much sorted me out. I'm still getting the error
> message that the dataAdapter is already declared but I don't know of any
> other way to get what I'm after for the oledb data adapter?
>
> "Stephany Young" <noone@xxxxxx> wrote in message
> news:OKFEjKz6IHA.5440@xxxxxx
Quote:

>> The OleDbCommand, in general but especially for JET, does not support
>> named parameters in the CommandText.
>>
>> Instead parameters are positional and designated by ?.
>>
>> So your CommandText then becomes:
>>
>> "SELECT * from tblAssets where asset_tag=?"
>>
>> The positional parameter is satisfied by the OleDbParameter in the
>> relative position in the Parameters collection so it is CRITICAL that
>> they are added in the correct sequence.
>>
>> When you defined an OleDbCommand, you must give it a name, even though it
>> is is ignored.
>>
>> So your parameter collection, is populated thus:
>>
>> assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
>> cboAsset.Text
>>
>> Note that I have demonstrated using 'asset-tag' so that it becomes
>> self-documenting to a degree.
>>
>> Also note that the Add method has a number of overloads that make
>> defining OleDBParameters easier.
>>
>> In addition, you do not HAVE to define the width of the column in
>> question. If you omit the width then it will be inferred at
>> execution-time.
>>
>> IIRC there is also a method AddWithValue so that you can add an
>> OleDbParameter thus:
>>
>> assCmd.Parameters.AddWithValue("asset_tag", cboAsset.Text)
>>
>> In this case both the type and the with of the column in question are
>> inferred at execution-time.
>>
>>
>> "bill" <bill@xxxxxx> wrote in message
>> news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

>>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;"
>>> & "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>> 2008\IT_Assets.mdb")
>>>
>>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>>
>>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>> asset_tag = @fn", Con)
>>>
>>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>>
>>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>
>>> Dim DT As New DataTable
>>>
>>> DataAdapter.Fill(DT)
>>>
>>> DataAdapter.Dispose()
>>>
>>> 'I'm hoping that this recordset will populate the grid but nothing
>>> happens?
>>>
>>> Me.DataGridView1.DataSource = DT
>>>
>>>
>>
>
>

My System SpecsSystem Spec
Old 07-21-2008   #2 (permalink)
PvdG42


 
 

Re: Can anyone tell me why this does not work?

"bill" <bill@xxxxxx> wrote in message
news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
> 2008\IT_Assets.mdb")
>
> Dim dataAdapter As OleDb.OleDbDataAdapter
>
> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
> asset_tag = @fn", Con)
>
> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>
> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>
> Dim DT As New DataTable
>
> DataAdapter.Fill(DT)
>
> DataAdapter.Dispose()
>
> 'I'm hoping that this recordset will populate the grid but nothing
> happens?
>
> Me.DataGridView1.DataSource = DT
>
>
No error message at all?
One thing I see is the use of single "\" in the connection string, which I
think should either be "\\" or "/".

My System SpecsSystem Spec
Old 07-21-2008   #3 (permalink)
Stanimir Stoyanov


 
 

Re: Can anyone tell me why this does not work?

> One thing I see is the use of single "\" in the connection string, which I
Quote:

> think should either be "\\" or "/".
In VB you do not have to escape slashes. The ConnectionString is fine as
long as the provider and data source are correctly defined.

Best Regards,
Stanimir Stoyanov | www.stoyanoff.info

"PvdG42" <pvdg@xxxxxx> wrote in message
news:u7b721y6IHA.4988@xxxxxx
Quote:

> "bill" <bill@xxxxxx> wrote in message
> news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>> 2008\IT_Assets.mdb")
>>
>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>
>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>> asset_tag = @fn", Con)
>>
>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>
>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>
>> Dim DT As New DataTable
>>
>> DataAdapter.Fill(DT)
>>
>> DataAdapter.Dispose()
>>
>> 'I'm hoping that this recordset will populate the grid but nothing
>> happens?
>>
>> Me.DataGridView1.DataSource = DT
>>
>>
My System SpecsSystem Spec
Old 07-21-2008   #4 (permalink)
Stephany Young


 
 

Re: Can anyone tell me why this does not work?

The OleDbCommand, in general but especially for JET, does not support named
parameters in the CommandText.

Instead parameters are positional and designated by ?.

So your CommandText then becomes:

"SELECT * from tblAssets where asset_tag=?"

The positional parameter is satisfied by the OleDbParameter in the relative
position in the Parameters collection so it is CRITICAL that they are added
in the correct sequence.

When you defined an OleDbCommand, you must give it a name, even though it is
is ignored.

So your parameter collection, is populated thus:

assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
cboAsset.Text

Note that I have demonstrated using 'asset-tag' so that it becomes
self-documenting to a degree.

Also note that the Add method has a number of overloads that make defining
OleDBParameters easier.

In addition, you do not HAVE to define the width of the column in question.
If you omit the width then it will be inferred at execution-time.

IIRC there is also a method AddWithValue so that you can add an
OleDbParameter thus:

assCmd.Parameters.AddWithValue("asset_tag", cboAsset.Text)

In this case both the type and the with of the column in question are
inferred at execution-time.


"bill" <bill@xxxxxx> wrote in message
news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
> 2008\IT_Assets.mdb")
>
> Dim dataAdapter As OleDb.OleDbDataAdapter
>
> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
> asset_tag = @fn", Con)
>
> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>
> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>
> Dim DT As New DataTable
>
> DataAdapter.Fill(DT)
>
> DataAdapter.Dispose()
>
> 'I'm hoping that this recordset will populate the grid but nothing
> happens?
>
> Me.DataGridView1.DataSource = DT
>
>
My System SpecsSystem Spec
Old 07-21-2008   #5 (permalink)
bill


 
 

Re: Can anyone tell me why this does not work?

I do get an error message here:
Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)

the dataAdapeter underlines and says "dataAdapter already declared in local
block" but I don't see what the problem is there?
Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
"data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
2008\IT_Assets.mdb")

Dim dataAdapter As OleDb.OleDbDataAdapter

Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
asset_tag=?")

assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value = cboAsset.Text

Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)

Dim DT As New DataTable

DataAdapter.Fill(DT)

DataAdapter.Dispose()

Me.DataGridView1.DataSource = DT

"PvdG42" <pvdg@xxxxxx> wrote in message
news:u7b721y6IHA.4988@xxxxxx
Quote:

> "bill" <bill@xxxxxx> wrote in message
> news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>> 2008\IT_Assets.mdb")
>>
>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>
>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>> asset_tag = @fn", Con)
>>
>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>
>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>
>> Dim DT As New DataTable
>>
>> DataAdapter.Fill(DT)
>>
>> DataAdapter.Dispose()
>>
>> 'I'm hoping that this recordset will populate the grid but nothing
>> happens?
>>
>> Me.DataGridView1.DataSource = DT
>>
>>
>
> No error message at all?
> One thing I see is the use of single "\" in the connection string, which I
> think should either be "\\" or "/".
>

My System SpecsSystem Spec
Old 07-21-2008   #6 (permalink)
bill


 
 

Re: Can anyone tell me why this does not work?

Thank you! You've pretty much sorted me out. I'm still getting the error
message that the dataAdapter is already declared but I don't know of any
other way to get what I'm after for the oledb data adapter?

"Stephany Young" <noone@xxxxxx> wrote in message
news:OKFEjKz6IHA.5440@xxxxxx
Quote:

> The OleDbCommand, in general but especially for JET, does not support
> named parameters in the CommandText.
>
> Instead parameters are positional and designated by ?.
>
> So your CommandText then becomes:
>
> "SELECT * from tblAssets where asset_tag=?"
>
> The positional parameter is satisfied by the OleDbParameter in the
> relative position in the Parameters collection so it is CRITICAL that they
> are added in the correct sequence.
>
> When you defined an OleDbCommand, you must give it a name, even though it
> is is ignored.
>
> So your parameter collection, is populated thus:
>
> assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
> cboAsset.Text
>
> Note that I have demonstrated using 'asset-tag' so that it becomes
> self-documenting to a degree.
>
> Also note that the Add method has a number of overloads that make defining
> OleDBParameters easier.
>
> In addition, you do not HAVE to define the width of the column in
> question. If you omit the width then it will be inferred at
> execution-time.
>
> IIRC there is also a method AddWithValue so that you can add an
> OleDbParameter thus:
>
> assCmd.Parameters.AddWithValue("asset_tag", cboAsset.Text)
>
> In this case both the type and the with of the column in question are
> inferred at execution-time.
>
>
> "bill" <bill@xxxxxx> wrote in message
> news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>> 2008\IT_Assets.mdb")
>>
>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>
>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>> asset_tag = @fn", Con)
>>
>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>
>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>
>> Dim DT As New DataTable
>>
>> DataAdapter.Fill(DT)
>>
>> DataAdapter.Dispose()
>>
>> 'I'm hoping that this recordset will populate the grid but nothing
>> happens?
>>
>> Me.DataGridView1.DataSource = DT
>>
>>
>

My System SpecsSystem Spec
Old 07-22-2008   #7 (permalink)
Jack Jackson


 
 

Re: Can anyone tell me why this does not work?

You declared dataAdapter twice.

Once on this line:
Quote:

>Dim dataAdapter As OleDb.OleDbDataAdapter
and again a few lines later on this line:
Quote:

>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
Just remove the first line.

On Mon, 21 Jul 2008 18:45:58 -0600, "bill" <bill@xxxxxx>
wrote:
Quote:

>I do get an error message here:
>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>
>the dataAdapeter underlines and says "dataAdapter already declared in local
>block" but I don't see what the problem is there?
>Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>"data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>2008\IT_Assets.mdb")
>
>Dim dataAdapter As OleDb.OleDbDataAdapter
>
>Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>asset_tag=?")
>
>assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value = cboAsset.Text
>
>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>
>Dim DT As New DataTable
>
>DataAdapter.Fill(DT)
>
>DataAdapter.Dispose()
>
>Me.DataGridView1.DataSource = DT
>
>"PvdG42" <pvdg@xxxxxx> wrote in message
>news:u7b721y6IHA.4988@xxxxxx
Quote:

>> "bill" <bill@xxxxxx> wrote in message
>> news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

>>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>>> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>> 2008\IT_Assets.mdb")
>>>
>>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>>
>>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>> asset_tag = @fn", Con)
>>>
>>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>>
>>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>
>>> Dim DT As New DataTable
>>>
>>> DataAdapter.Fill(DT)
>>>
>>> DataAdapter.Dispose()
>>>
>>> 'I'm hoping that this recordset will populate the grid but nothing
>>> happens?
>>>
>>> Me.DataGridView1.DataSource = DT
>>>
>>>
>>
>> No error message at all?
>> One thing I see is the use of single "\" in the connection string, which I
>> think should either be "\\" or "/".
>>
>
My System SpecsSystem Spec
Old 07-22-2008   #8 (permalink)
bill


 
 

Re: Can anyone tell me why this does not work?

It still errors out there. I'm stumped!

"Jack Jackson" <jjackson@xxxxxx> wrote in message
news:42pa84p16sgvmj1prevpsn453tk42a4r17@xxxxxx
Quote:

> You declared dataAdapter twice.
>
> Once on this line:
Quote:

>>Dim dataAdapter As OleDb.OleDbDataAdapter
>
> and again a few lines later on this line:
Quote:

>>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>
> Just remove the first line.
>
> On Mon, 21 Jul 2008 18:45:58 -0600, "bill" <bill@xxxxxx>
> wrote:
>
Quote:

>>I do get an error message here:
>>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>
>>the dataAdapeter underlines and says "dataAdapter already declared in
>>local
>>block" but I don't see what the problem is there?
>>Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>>"data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>2008\IT_Assets.mdb")
>>
>>Dim dataAdapter As OleDb.OleDbDataAdapter
>>
>>Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>asset_tag=?")
>>
>>assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
>>cboAsset.Text
>>
>>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>
>>Dim DT As New DataTable
>>
>>DataAdapter.Fill(DT)
>>
>>DataAdapter.Dispose()
>>
>>Me.DataGridView1.DataSource = DT
>>
>>"PvdG42" <pvdg@xxxxxx> wrote in message
>>news:u7b721y6IHA.4988@xxxxxx
Quote:

>>> "bill" <bill@xxxxxx> wrote in message
>>> news:u6U3Wgw6IHA.1192@xxxxxx
>>>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;"
>>>> &
>>>> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>>> 2008\IT_Assets.mdb")
>>>>
>>>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>>>
>>>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>>> asset_tag = @fn", Con)
>>>>
>>>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>>>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>>>
>>>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>>
>>>> Dim DT As New DataTable
>>>>
>>>> DataAdapter.Fill(DT)
>>>>
>>>> DataAdapter.Dispose()
>>>>
>>>> 'I'm hoping that this recordset will populate the grid but nothing
>>>> happens?
>>>>
>>>> Me.DataGridView1.DataSource = DT
>>>>
>>>>
>>>
>>> No error message at all?
>>> One thing I see is the use of single "\" in the connection string, which
>>> I
>>> think should either be "\\" or "/".
>>>
>>

My System SpecsSystem Spec
Old 07-22-2008   #9 (permalink)
Jack Jackson


 
 

Re: Can anyone tell me why this does not work?

Are you saying that you still get the error "dataAdapter already
declared in local block"? If so, then you must still have more than
one definition of dataAdapter in the routine. If you can't figure it
out post the entire routine.

On Mon, 21 Jul 2008 22:54:37 -0600, "bill" <bill@xxxxxx>
wrote:
Quote:

>It still errors out there. I'm stumped!
>
>"Jack Jackson" <jjackson@xxxxxx> wrote in message
>news:42pa84p16sgvmj1prevpsn453tk42a4r17@xxxxxx
Quote:

>> You declared dataAdapter twice.
>>
>> Once on this line:
Quote:

>>>Dim dataAdapter As OleDb.OleDbDataAdapter
>>
>> and again a few lines later on this line:
Quote:

>>>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>
>> Just remove the first line.
>>
>> On Mon, 21 Jul 2008 18:45:58 -0600, "bill" <bill@xxxxxx>
>> wrote:
>>
Quote:

>>>I do get an error message here:
>>>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>
>>>the dataAdapeter underlines and says "dataAdapter already declared in
>>>local
>>>block" but I don't see what the problem is there?
>>>Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;" &
>>>"data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>>2008\IT_Assets.mdb")
>>>
>>>Dim dataAdapter As OleDb.OleDbDataAdapter
>>>
>>>Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>>asset_tag=?")
>>>
>>>assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
>>>cboAsset.Text
>>>
>>>Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>
>>>Dim DT As New DataTable
>>>
>>>DataAdapter.Fill(DT)
>>>
>>>DataAdapter.Dispose()
>>>
>>>Me.DataGridView1.DataSource = DT
>>>
>>>"PvdG42" <pvdg@xxxxxx> wrote in message
>>>news:u7b721y6IHA.4988@xxxxxx
>>>> "bill" <bill@xxxxxx> wrote in message
>>>> news:u6U3Wgw6IHA.1192@xxxxxx
>>>>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;"
>>>>> &
>>>>> "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>>>> 2008\IT_Assets.mdb")
>>>>>
>>>>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>>>>
>>>>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>>>> asset_tag = @fn", Con)
>>>>>
>>>>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>>>>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>>>>
>>>>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>>>
>>>>> Dim DT As New DataTable
>>>>>
>>>>> DataAdapter.Fill(DT)
>>>>>
>>>>> DataAdapter.Dispose()
>>>>>
>>>>> 'I'm hoping that this recordset will populate the grid but nothing
>>>>> happens?
>>>>>
>>>>> Me.DataGridView1.DataSource = DT
>>>>>
>>>>>
>>>>
>>>> No error message at all?
>>>> One thing I see is the use of single "\" in the connection string, which
>>>> I
>>>> think should either be "\\" or "/".
>>>>
>>>
>
My System SpecsSystem Spec
Old 07-23-2008   #10 (permalink)
Stephany Young


 
 

Re: Can anyone tell me why this does not work?

You've got it declared twice.


"bill" <bill@xxxxxx> wrote in message
news:Oq0CQT56IHA.4864@xxxxxx
Quote:

> Thank you! You've pretty much sorted me out. I'm still getting the error
> message that the dataAdapter is already declared but I don't know of any
> other way to get what I'm after for the oledb data adapter?
>
> "Stephany Young" <noone@xxxxxx> wrote in message
> news:OKFEjKz6IHA.5440@xxxxxx
Quote:

>> The OleDbCommand, in general but especially for JET, does not support
>> named parameters in the CommandText.
>>
>> Instead parameters are positional and designated by ?.
>>
>> So your CommandText then becomes:
>>
>> "SELECT * from tblAssets where asset_tag=?"
>>
>> The positional parameter is satisfied by the OleDbParameter in the
>> relative position in the Parameters collection so it is CRITICAL that
>> they are added in the correct sequence.
>>
>> When you defined an OleDbCommand, you must give it a name, even though it
>> is is ignored.
>>
>> So your parameter collection, is populated thus:
>>
>> assCmd.Parameters.Add("asset_tag", OleDbType.VarChar).Value =
>> cboAsset.Text
>>
>> Note that I have demonstrated using 'asset-tag' so that it becomes
>> self-documenting to a degree.
>>
>> Also note that the Add method has a number of overloads that make
>> defining OleDBParameters easier.
>>
>> In addition, you do not HAVE to define the width of the column in
>> question. If you omit the width then it will be inferred at
>> execution-time.
>>
>> IIRC there is also a method AddWithValue so that you can add an
>> OleDbParameter thus:
>>
>> assCmd.Parameters.AddWithValue("asset_tag", cboAsset.Text)
>>
>> In this case both the type and the with of the column in question are
>> inferred at execution-time.
>>
>>
>> "bill" <bill@xxxxxx> wrote in message
>> news:u6U3Wgw6IHA.1192@xxxxxx
Quote:

>>> Dim Con = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;"
>>> & "data source=c:\_Archive\Documentation - Projects\Hardware Tracking -
>>> 2008\IT_Assets.mdb")
>>>
>>> Dim dataAdapter As OleDb.OleDbDataAdapter
>>>
>>> Dim assCmd As New OleDb.OleDbCommand("SELECT * from tblAssets where
>>> asset_tag = @fn", Con)
>>>
>>> assCmd.Parameters.Add(New OleDb.OleDbParameter("@fn",
>>> OleDb.OleDbType.VarChar, 30)).Value = Me.cboAsset.Text
>>>
>>> Dim dataAdapter As New OleDb.OleDbDataAdapter(assCmd, Con)
>>>
>>> Dim DT As New DataTable
>>>
>>> DataAdapter.Fill(DT)
>>>
>>> DataAdapter.Dispose()
>>>
>>> 'I'm hoping that this recordset will populate the grid but nothing
>>> happens?
>>>
>>> Me.DataGridView1.DataSource = DT
>>>
>>>
>>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
speakers randomly wont work sometimes on laptop but external will sometime work Sound & Audio
Still searching for way to get Vista search to work: Why doesn't FilterFilesWithUnknownExtensions registry key work in Vista? Vista General
all cd's don't work, but dvd's still work Vista hardware & devices
HP LaserJet 1010 don't work in Vista since Beta2 - Advanced 1384 Printing Support drivers for XP don't work Vista print fax & scan
Will all the programs that work on xp work on vista? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46