SQL Server Data base connection code:-
// Create object for SqlConnection
SqlConnection con=new SqlConnection(@”Network Library=DBMSSOCN;Data Source=XXXX; database=XXXXX;User id=XXXX;Password=XXXX;");
//Connect the SQL Server
con.Open();
// create object for query execution
SqlCommand dbcommand = con.CreateCommand();
dbcommand.CommandText = "Select * from tablename";
//For data reading from query result table create data reader
SqlDataReader dbReader = dbcommand.ExecuteReader();
//get the columns count from query table
int fieldcount = dbReader.FieldCount;
// There is no direct command for record count but with below code find query result table having one or more records.
Boolean result = dbReader.HasRows;
// Close the reader object
dbReader.Close();
//get the DB column Data from reader :-
dbReader[“Field Name”]
No comments:
Post a Comment