What type of database?
Does it allow the DESCRIBE or DESC command to be used on a table?
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Some databases have a DESCRIBE method that tells the columns of a table.
SQL Server does not.
You can, however, retrieve the columns of a table by querying the COLUMNS table under the owner INFORMATION_SCHEMA under your given database.
Let's say you have a database named E911 and a table named JipAreaCode.
SELECT
COLUMN_NAME,
ORDINAL_POSITION
FROM
E911.INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='JipAreaCode'
Assuming you're comfortable with turning SQL Queries into VB Code, you can set up a query to check the columns and positions and compare that to what the user is trying to input.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Here is another method that uses the NorthWind database as an example. Probably not the best solution but it IS "a" solution.
Dim con As New ADODB.Connection
con.Open("Driver={SQL Server};Server=.\SQLEXPRESS;Database=NorthWind;Trusted_Connection=yes;")
Dim rec As New ADODB.Recordset
rec.Open("select top 1 * from Categories", con, CursorTypeEnum.adOpenForwardOnly)
For i As Integer = 0 To rec.Fields.Count - 1
MsgBox(rec.Fields(i).Name)
Next
rec.Close()
con.Close()
Each iteration through the loop displays the name of the next field.
Reverend Jim
Carpe per diem
3,596 posts since Aug 2010
Reputation Points: 561
Solved Threads: 446
Skill Endorsements: 32
Question Answered as of 1 Year Ago by
thines01,
Reverend Jim
and
poojavb