TesT For SQL Connection

by ssi 15. December 2015 15:33
private bool GotConnected2SQL(string sConnectionString)
     {
         bool bRet = false;
         SqlConnection mySQLConnection = new SqlConnection(sConnectionString);
         string SQLStatement = "SELECT control FROM [tbvl_ssi_control]";
         string sSql = string.Format(SQLStatement);
         SqlCommand mySQLCommand = mySQLConnection.CreateCommand();
         try
         {
             mySQLCommand.CommandText = sSql;
             SqlDataAdapter mySQLDataAdapter = new SqlDataAdapter();
             mySQLDataAdapter.SelectCommand = mySQLCommand;
             DataSet myDataSet = new DataSet();
 
             mySQLConnection.Open();
             Console.WriteLine("Retrieving rows from the Query");
             mySQLDataAdapter.Fill(myDataSet, "RECS");
             mySQLConnection.Close();
             DataTable myDataTable = myDataSet.Tables["RECS"];
             bRet = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(string.Format("""SQL Connection Error: {0}", ex.Message), "SQL Connection Status"MessageBoxButtons.OK, MessageBoxIcon.Error);
             bRet = false;
         }
 
         return bRet;
     }

Tags: , ,

CSharp | SQL

Add comment

biuquote
  • Comment
  • Preview
Loading

Calendar

<<  September 2025  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"A woman's guess is much more accurate than a man's certainty."
Rudyard Kipling