I have 3 sqlquery string , the first query result i would like to fill in to datagridview columns1 the secound sqlquery result i would like to fill in to datagridview columns2
some one can help me on this?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 24, 2011, 7:23 PM EST
Run the attachments.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Datagridview_bind
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select customer.custname,product.prodname from customer, product where customer.prodid = product.prodid";
com = new OleDbCommand(str, con);
oda = new OleDbDataAdapter(com);
ds = new DataSet();
oda.Fill(ds, "customer");
dataGridView1.DataMember = "customer";
dataGridView1.DataSource = ds;
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer
meko weldys6 reputationPosted Nov 24, 2011, 10:23 PM EST
string strSQL2;
int volt = 250;
DataTable table = new DataTable();
while (volt <= 775)
{
strSQL1 = " SELECT COUNT(ID) [column1] FROM [tablename]" +
" WHERE (ID = '112') AND (DVolt BETWEEN " + volt + " AND (" + volt + "+ 25)) AND (APower / (RPower) BETWEEN 0.0 AND 0.05)";
strSQL2 = " SELECT COUNT(ID)[column2] FROM [tablename]" +
" WHERE (ID = '112') AND (DVolt BETWEEN " + volt + " AND (" + volt + "+ 25)) AND (Apower / (RPower) BETWEEN 0.05 AND 0.1)";
volt = volt + 25;
using (SqlConnection conn = new SqlConnection(string connection)
{
conn.Open();
using (SqlDataAdapter adapter1 = new SqlDataAdapter(strSQL1, conn))
{
adapter1 .Fill(table) ;
dataGridView1.DataSource = table ;
}
using (SqlDataAdapter adapter2 = new SqlDataAdapter(strSQL2, conn))
{
adapter2.Fill(table);
dataGridView1.DataSource = table;
}
conn.close();
}
}
This is my code, I am able to fill the column1 and column2 in dataGridView1 but the rows are not proportinal.
I need help
regard
Meko
meko weldys6 reputationPosted Nov 27, 2011, 10:52 PM EST
Have you looked my code? if you have any Idea please let me know.
Regard
Meko