i want to display two columns in datagrid view . first by sql-table second is unbounded where i want some selection button which tells which row in selected.
i 从表上列第1栏,但无法说明如何增加第二栏。 下面是我的法典。
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string constring = @"server=.SQLSER;database=test1;integrated security=true;";
string sql = @"select rel.depar from rel RIGHT OUTER JOIN cust on cust.id=rel.id";
SqlConnection con = new SqlConnection(constring);
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader red = cmd.ExecuteReader();
dataGridView1.ColumnCount = 2;
dataGridView1.Columns[0].Name = "department";
dataGridView1.Columns[1].Name = "unboundcolumn";
while (red.Read())
{
dataGridView1.Rows.Add(red["depar"]);
}
red.Close();
con.Close();
}
}
}