'Return sql command in C#
how should i return this command in c# ?
SELECT COUNT(id_pac) AS Expr1, data
FROM programare
GROUP BY data
private void button1_Click(object sender, EventArgs e)
{
programareTableAdapter.Cerinta_3(_BD_AtestatDataSet.programare);
DataTable dt = _BD_AtestatDataSet.programare;
}
Solution 1:[1]
Perhaps an introduction to Microsoft's ADO.NET code, the System.Data.SqlClient in particular if you are dealing with SQL Server. A quick example:
using (SqlConnection conn = new SqlConnection("YourConnectionStringToDatabaseHere"))
{
conn.Open();
// using a command to retrieve active orders
using (SqlCommand cmd = new SqlCommand("SELECT COUNT(id_pac) AS Expr1, data
FROM programare
GROUP BY data", conn))
{
// get a sqlreader with the results from our query
using (var reader = cmd.ExecuteReader())
{
// while there is a record to be read
while (reader.Read())
{
int index = 1;
var count = reader.GetInt32(index++);
var data = reader.GetString(index++);
}
}
}
}
I didn't get to test my code in particular, but it should give you an idea where to start.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ibrennan208 |
