currently, what i want to do is, add a column in a table "default" during runtime. Well, I've got that covered already.

The problem is, the column names are actually taken from the users input through a textbox or drop down list and of course, if the same column is added already in the table, it generates an error since it has to be unique.

That is why i wonder if it is possible to know if a column already exists without viewing the form which contains the grid view of that table?

Featured Replies in this Discussion

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. ... Assuming you're comfortable with turning SQL Queries into VB Code, you can set up a query to check the columns and positions…

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.

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()

currently, what i want to do is, add a column in a table "default" during runtime. Well, I've got that covered already.

The problem is, the column names are actually taken from the users input through a textbox or drop down list and of course, if the same column is added already in the table, it generates an error since it has to be unique.

That is why i wonder if it is possible to know if a column already exists without viewing the form which contains the grid view of that table?

Thanks if you can help :$

What u can do is....

before inserting the value into database u need to check if the value exists in the table
using the select query

"select colname from tablename where colname="'+textbox1.text+"'"

If the reader returns a true value then u shid not save the value in the database instead show a msg box that value already exists...