tags:

views:

342

answers:

1

considering this code

  Dim cn As New ADODB.Connection, cn2 As New ADODB.Connection
                        Dim rs As ADODB.Recordset
                        Dim connString As String
                        Dim SelectFieldName

                        Set cn = CurrentProject.Connection
                        SelectFieldName = astrFields(intIx)
                        Set rs = cn.OpenSchema(adSchemaColumns, _
                        Array(Empty, Empty, Empty, SelectFieldName))

strsql = select field from rs!tablename

Now i understand that this will work in VBA by getting the table name where the field is present.

I just want to know what would be C sharp equivalent for this piece of code?

A: 

Using System.Data.SqlClient;

//////now use following codes to retrieve data//////
String ConStr = "Data Source=localhost;Initial Catalog=Database Name;Integrated Security=True";
SqlConnection sqlcnn;
SqlCommand sqlcmd;
SqlDataReader sqldr;
string plssql;
plssql = "select field from table_name where condition";
sqlcnn = new SqlConnection(ConStr);
sqlcnn.Open();
sqlcmd = new SqlCommand(plssql, sqlcnn);
sqldr = sqlcmd.ExecuteReader();
String val=sqldr["field name"].ToString();
sqlcmd.Close();
sqlcnn.Close();

Chris
------
Convert your Excel spreadsheet into an online calculator.
http://www.spreadsheetconverter.com