Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Understanding Parameters of Command objects

Status
Not open for further replies.

nells1

Programmer
Mar 17, 2003
28
CA
Hi all

I'm very new to vb.net and ADO.net. I am trying to connect to a mysql database.. i've managed that :D Now I'm working on the Update, Delete and Insert commands. I don't want to hard code the parameters for these commands as in all the examples i can find.. ie:

Code:
selectCMD.Parameters.Add("@Country", OleDbType.VarChar, 15).Value = "UK"

Instead I would like it to read the columns from my dataset and add those as parameters. Has anyone tried to do this?? ie:

Code:
For Each Column In ds.Tables(0).Columns()
    ColumnName = Column.ColumnName.ToString
    ColumnType = Column.DataType()
    da.UpdateCommand.Parameters.Add(ColumnName, ColumnType)
    
Next Column

This code doesn't work. I need to give the parameter a OleDb.OleDbType argument (
Code:
ColumnType
) to specify the datatype of the field. The only datatype I can get out of the dataset is of type
Code:
System.Type
(
Code:
Column.DataType()
). I cannot figure out how to convert
Code:
System.Type
to
Code:
OleDb.OleDbType
.

I must be missing something... it can't be this hard. Unfortunately I can't use the built in CommandBuilder to make all these lovely things for me because i only have the standard edition of vb.net and that doesn't do all the handy stuff for non-microsoft databases. argh.

Any help would be appreciated.

Cheers
nells
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top