Hesham Hassanein

Hesham Hassanein

  • NA
  • 140
  • 17k

multiple sql queries in c#

Sep 23 2014 5:28 AM
Hello,
 
I have 5 letters in a database that i want to read and return. so I am using sqlconnection in c#.
I have wrote a small code but i want to know what is missing. Will this work?. Thanks for the help
 
Do i have to use adapter fill??.. I mean does the following code provide the the 5 letters and return them??
 
static DataTable SMSTable(DataTable dtt)
{

using (MySqlConnection connection = new MySqlConnection("server=10.2.151.147;port=3306;database=MR_61_MSDB"))
{
connection.Open();
if (connection.State == ConnectionState.Open)
{
string sql1 = "Select intMobileID, strTasten_Name,dblX_Wert,dblY_Wert,dblZ_Wert from [Tastatur_Daten] Where intMobileID=1144 AND strTasten_Name=" + "H";
string sql2 = "Select intMobileID, strTasten_Name,dblX_Wert,dblY_Wert,dblZ_Wert from [Tastatur_Daten] Where intMobileID=1144 AND strTasten_Name=" + "A";
string sql3 = "Select intMobileID, strTasten_Name,dblX_Wert,dblY_Wert,dblZ_Wert from [Tastatur_Daten] Where intMobileID=1144 AND strTasten_Name=" + "L";
string sql4 = "Select intMobileID, strTasten_Name,dblX_Wert,dblY_Wert,dblZ_Wert from [Tastatur_Daten] Where intMobileID=1144 AND strTasten_Name=" + "L";
string sql5 = "Select intMobileID, strTasten_Name,dblX_Wert,dblY_Wert,dblZ_Wert from [Tastatur_Daten] Where intMobileID=1144 AND strTasten_Name=" + "O";

using (MySqlCommand command = new MySqlCommand(sql1, connection))
{

using (MySqlDataReader reader = command.ExecuteReader())
{

}

}

using (MySqlCommand command = new MySqlCommand(sql2, connection))
{


using (MySqlDataReader reader = command.ExecuteReader())
{

}

}


using (MySqlCommand command = new MySqlCommand(sql3, connection))
{

using (MySqlDataReader reader = command.ExecuteReader())
{

}

}

using (MySqlCommand command = new MySqlCommand(sql4, connection))
{

using (MySqlDataReader reader = command.ExecuteReader())
{

}

}
using (MySqlCommand command = new MySqlCommand(sql5, connection))
{

using (MySqlDataReader reader = command.ExecuteReader())
{

}

}
}
else
{
MessageBox.Show("Could not connect to database!");
}

return (dtt);
}
}
 

Answers (1)