1 Answer, 1 is accepted
Hi Alexis,
If I have correctly understood your scenario, you want to create a custom query with the results you want to show in the RadGridView control. For your convenience, I have created a sample code to demonstrate how you can join two tables and show the result in the RadGridView. You can update the connection string with your database name and modify the SQL query to reflect the table names in your database.
public partial class Form1 : Form
{
private string connectionString = "Server=(local);Database=Retail_POS_System;Trusted_Connection=True;";
SqlConnection sqlConnection;
SqlCommand sqlCommand;
SqlDataReader sqlDataReader;
SqlDataAdapter sqlDataAdapter;
DataSet ds;
public Form1()
{
InitializeComponent();
this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
sqlConnection = new SqlConnection(connectionString);
sqlConnection.Close();
sqlConnection.Open();
sqlCommand = new SqlCommand("Select POSDeviceDefination.NAME, POSDeviceType.DeviceName From POSDeviceDefination INNER JOIN POSDeviceType On POSDeviceDefination.TYPE = POSDeviceType.DeviceID", sqlConnection);
sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (sqlDataReader.HasRows)
{
ds = new DataSet();
sqlDataReader.Close();
sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlDataAdapter.Fill(ds);
DataTable table = ds.Tables[0];
this.radGridView1.DataSource = table;
}
sqlConnection.Close();
}
}
Here is the result:
I hope that this is what you are looking for.
Regards,
Dinko | Tech Support Engineer
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Alexis,
It depends on the case. Probably creating a Store Procedure (SP) and then binding the RadGridView to its result will be cleaner. Bascically, SP potentially could lead to better performance compared to SQL in code. If you have an option of creating SP, I would recommend this approach and bind the RadGridView to it using the Data Source Configuration Wizard.