473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

"Insert Into tbl1 Values(" & dynamicParams & ")" ?

Hello,

I have to create a table in an Access mdb (remotely) on
the fly.

Create Table tbl1(fld1 Integer, fld2 varchar(10), fld3...)

Then I have to insert data:

Insert Into tbl1 Values(" & val1 & ", '" & val2 & "',...")"

I would like to make this dynamic rather than hardcoding
the parameters. Is there some kind of object that I could
populate with the parameters that I need to use to create
tbl1 or even just to insert values into tbl1? The idea is
to make this dynamic because the table I have to create on
the fly will vary in number of columns. So rather than
hardcoding these parameters I wanted to loop through a
resultset to see how many columns I need (and what
datatypes) and then create and populate the table using an
ADO command object, unless there is a better way.

Thanks,
Rich
Nov 20 '05 #1
6 1912
"Rich" <an*******@discussions.microsoft.com> wrote in message
news:25*****************************@phx.gbl...
Hello,

I have to create a table in an Access mdb (remotely) on
the fly.

Create Table tbl1(fld1 Integer, fld2 varchar(10), fld3...)

Then I have to insert data:

Insert Into tbl1 Values(" & val1 & ", '" & val2 & "',...")"

I would like to make this dynamic rather than hardcoding
the parameters. Is there some kind of object that I could
populate with the parameters that I need to use to create
tbl1 or even just to insert values into tbl1? The idea is
to make this dynamic because the table I have to create on
the fly will vary in number of columns. So rather than
hardcoding these parameters I wanted to loop through a
resultset to see how many columns I need (and what
datatypes) and then create and populate the table using an
ADO command object, unless there is a better way.


Look at the OleDbDataAdapter and OleDbCommandBuilder. They do that already.

David
Nov 20 '05 #2
Thanks for your reply. Yes, I am familiar with Command
Builder. I confess, that I am using com ADO in a Non
DotNet application. I was hoping there was some VB object
or technique that I wasn't familiar with for not having to
hardcode parameters. Thinking outloud here I am thinking
maybe I could make up a kind of library file with
parameter lists I could use. Basically, I am just making
sure there isn't some kind of functionality for the
Command object that I wasn't familiar with before I start
re-inventing the wheel :).

Rich

-----Original Message-----
"Rich" <an*******@discussions.microsoft.com> wrote in messagenews:25*****************************@phx.gbl...
Hello,

I have to create a table in an Access mdb (remotely) on
the fly.

Create Table tbl1(fld1 Integer, fld2 varchar(10), fld3...)
Then I have to insert data:

Insert Into tbl1 Values(" & val1 & ", '" & val2 & "',...")"
I would like to make this dynamic rather than hardcoding
the parameters. Is there some kind of object that I could populate with the parameters that I need to use to create tbl1 or even just to insert values into tbl1? The idea is to make this dynamic because the table I have to create on the fly will vary in number of columns. So rather than
hardcoding these parameters I wanted to loop through a
resultset to see how many columns I need (and what
datatypes) and then create and populate the table using an ADO command object, unless there is a better way.

Look at the OleDbDataAdapter and OleDbCommandBuilder.

They do that already.
David
.

Nov 20 '05 #3

"Rich" <an*******@discussions.microsoft.com> wrote in message
news:25*****************************@phx.gbl...
Thanks for your reply. Yes, I am familiar with Command
Builder. I confess, that I am using com ADO in a Non
DotNet application. I was hoping there was some VB object
or technique that I wasn't familiar with for not having to
hardcode parameters. Thinking outloud here I am thinking
maybe I could make up a kind of library file with
parameter lists I could use. Basically, I am just making
sure there isn't some kind of functionality for the
Command object that I wasn't familiar with before I start
re-inventing the wheel :).

Rich


Ado has the recordset. Just open a recordset against the new table and the
recordset will suck up all the table metadata. Add rows to the recordset
and then recordset.update will save them to the database.

David

Nov 20 '05 #4

"Rich" <an*******@discussions.microsoft.com> wrote in message
news:25*****************************@phx.gbl...
Thanks for your reply. Yes, I am familiar with Command
Builder. I confess, that I am using com ADO in a Non
DotNet application.
Then why are you asking in a .NET group? Try
microsoft.public.vb.database.ado or microsoft.public.vb.general.discussion.
I was hoping there was some VB object
or technique that I wasn't familiar with for not having to
hardcode parameters. Thinking outloud here I am thinking
maybe I could make up a kind of library file with
parameter lists I could use. Basically, I am just making
sure there isn't some kind of functionality for the
Command object that I wasn't familiar with before I start
re-inventing the wheel :).


You can

-- open a Recordset and check its Fields
-- use the OpenSchema method of the Connection(?) object
-- use the ADOX library.
Nov 20 '05 #5
Hi Rich,

I could never find a sample about the use of parameters in OleDb so I have
made one.

Let me know if this makes it more clear to you? (The used datagrid is a
webgrid because this does not work with a windowsform grid, however that is
only to show that the sample is correct, without the grid all is the same).

Cor
\\\
cmd.CommandText = "INSERT INTO tblUsers (UserId, Firstname) " & _
"VALUES (@UserId, '@Name')"
conn.Open()
Dim myparam1 As New OleDb.OleDbParameter("@UserId", _
OleDb.OleDbType.Integer)
Dim myparam2 As New OleDb.OleDbParameter("@Name", _
OleDb.OleDbType.VarWChar)
cmd.Parameters.Add(myparam1)
cmd.Parameters.Add(myparam2)
myparam1.Value = 1
myparam2.Value = "Manuel"
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
cmd.Parameters.Add(myparam2)
cmd.Parameters.Add(myparam1)
myparam2.Value = "Terry"
cmd.CommandText = ("UPDATE tblUsers " & _
"SET FirstName=@Name WHERE UserID=@userId")
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
cmd.Parameters.Add(myparam1)
cmd.CommandText = "Select * from tblUsers " & _
"where (UserId = @UserId)"
Dim dr As OleDb.OleDbDataReader
dr = cmd.ExecuteReader()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
conn.Close()
///

Nov 20 '05 #6
Yes, well, I have had problems with the ADO recordset
object in vbscripting, so I had put it out of my mind.
But now I think I should invoke it (give it a try).

As for posting in the com vb newsgroup, well, I admit that
I did post something similar but no solutions. Just
thought maybe someone here might have another
perspective. And yes. The ADO recordset object. I just
can't think why I totally blocked it out of my mind.

Well, thanks all.
Rich

-----Original Message-----
Thanks for your reply. Yes, I am familiar with Command
Builder. I confess, that I am using com ADO in a Non
DotNet application. I was hoping there was some VB objector technique that I wasn't familiar with for not having tohardcode parameters. Thinking outloud here I am thinking
maybe I could make up a kind of library file with
parameter lists I could use. Basically, I am just making
sure there isn't some kind of functionality for the
Command object that I wasn't familiar with before I start
re-inventing the wheel :).

Rich

-----Original Message-----
"Rich" <an*******@discussions.microsoft.com> wrote inmessage
news:25*****************************@phx.gbl.. .
Hello,

I have to create a table in an Access mdb (remotely) on
the fly.

Create Table tbl1(fld1 Integer, fld2 varchar(10),fld3...)
Then I have to insert data:

Insert Into tbl1 Values(" & val1 & ", '" & val2& "',...")"
I would like to make this dynamic rather than hardcoding the parameters. Is there some kind of object that Icould populate with the parameters that I need to use tocreate tbl1 or even just to insert values into tbl1? The
ideais to make this dynamic because the table I have to
create
on the fly will vary in number of columns. So rather than
hardcoding these parameters I wanted to loop through a
resultset to see how many columns I need (and what
datatypes) and then create and populate the table
using
an ADO command object, unless there is a better way.


Look at the OleDbDataAdapter and OleDbCommandBuilder.

They do that already.

David
.

.

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
1
by: newbie_mw | last post by:
Seems my post was buried in more cries for help :-) I will try again. It's probably a very novice question so please take a look! Thanks!...
9
by: Luc Dal | last post by:
Hello, I've serious problem using ASP under WindowsXP sp2. I get the following reply (sorry it's in french) Erreur de compilation Microsoft VBScript error '800a0401' Fin d'instruction...
5
by: Chad Richardson | last post by:
Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5...
2
by: CFW | last post by:
I use the following flawlessly to insert a single field: strSQL = "Insert into (Casket) Values " _ & "(" & conQuote & NewCasket & conQuote & ")" Set db = CurrentDb If MsgBox(NewCasket & " is...
3
by: Ed | last post by:
Hi, I want to load data to a table in Sql Server from a dataset table in my vb.net app using a dataAdapter. I know how to do this as follows (my question is to see if I can reduce the amount...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
0
by: MarceloLinero | last post by:
Hi, i`m problem whith it !! help me ! No found way for insert in table directy in database sql express and no undertand why ! steps in general: 1. create coneccion ready 2. declarate a...
3
by: =?Utf-8?B?UmljaA==?= | last post by:
I need to build a sql string that looks like this: strSql = "Select * from tbl1 Where x In (123,456,789)" or strSql = "Select * from tbl1 Where x In (123,456,789,527,914)" The numbers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.