本文介绍了连接3表并绑定到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨frnds正在从数据库中加入3个表并将其绑定到网格视图中我的任务....我完成了编码,但我的表单没有响应并且在此行中敲击
Hi frnds am joing 3 table from database and bind that to an grid view it my task.... I done the coding but my form is no responding and struck at this line
da.Fill(dt);
我的complite代码是
And my complite code is
da = new SqlDataAdapter("SELECT classify21.Age, classify21.workclass, classify21.fnlwgt, classify22.maritalstatus, classify23.educationnum FROM classify21 INNER JOIN classify22 on classify21.workclass=classify22.workclass INNER JOIN classify23 on classify22.workclass = classify23.workclass",cn.con);
dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
请帮帮我谢谢...,
Pls do help me Thank You...,
推荐答案
using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
//
// You need to access the project's connection string here.
//
string connectionString ="your connection string";
//
// Create new SqlConnection object.
//
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
//
// Create new SqlCommand object.
//
using (SqlCommand command = new SqlCommand("SELECT classify21.Age, classify21.workclass, classify21.fnlwgt, classify22.maritalstatus, classify23.educationnum FROM classify21 INNER JOIN classify22 on classify21.workclass=classify22.workclass INNER JOIN classify23 on classify22.workclass = classify23.workclass", connection))
{
//
// Invoke ExecuteReader method.
//
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
GridView1.DataSource=reader;
GridView1.DataBind();
}
}
}
}
}
这篇关于连接3表并绑定到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!