How can we handle the SELECT statement if we don’t know the column_names
with my little experience if i have the following query
SELECT * FROM emp
i would do
While sqlReader.Read()
Dim name as string = sqlReader.Item("emp_name")
End While
Question
but what if i don’t know the number and columns names of what i’m getting
is there is any method of handling this
a method that tell us that there is x number of columns selected and their names
and then return this as a list of string , i don’t know if this is important or not but i’m doing this as a web service
You can use the
FieldCountproperty ofSystem.Data.SqlClient.SqlDataReaderto get the number of fields. You can then use theGetNameproperty to get the field names.http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx