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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
meko weldysPosted Nov 28, 2011, 3:52 AM
Have you looked my code? if you have any Idea please let me know.
Regard
Meko
meko weldysPosted Nov 25, 2011, 3:23 AM
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
Satyapriya NayakPosted Nov 25, 2011, 12:23 AM
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