add binding source
dbBindingSource = bindnge source1
dbGridview = grid1
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.SqlClient;
namespace database_v3
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
string strCon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=DataDirectory\\sakerDB.mdf;Integrated Security=True;User Instance=True";
string strSQL = "SELECT Brukernavn, antallnye + antallall AS Expr1, Dato FROM test_1";
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
dbBindSource.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
// finally bind the data to the grid
dbGridView.DataSource = dbBindSource;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
}
}
Abonner på:
Legg inn kommentarer (Atom)
Ingen kommentarer:
Legg inn en kommentar