dave4583

dave4583
- Name: [not set]
- Favorite Languages: [not set]
- Website: [not set]
- Location: [not set]
- About Me: [not set]
-
C# Tutorial - Binding a DataGridView to a Database
08/27/2010 - 03:46
Ok I would hate to say how long I've spent on this but I just deleted the 3 date/time columns(that were empty) and it now works. Have added them back in and it appears to be working, but I won't hold my breath.
Dave
-
C# Tutorial - Binding a DataGridView to a Database
08/27/2010 - 00:01
just learning c#
Have the update on a button_click as below but keep getting this error message
System.Data.OleDb.OleDbException was unhandled
Message=Syntax error (missing operator) in query expression '((EID = ?) AND ((? = 1 AND Tag IS NULL) OR (Tag = ?)) AND ((? = 1 AND BID IS NULL) OR (BID = ?)) AND ((? = 1 AND Sex IS NULL) OR (Sex = ?)) AND ((? = 1 AND Size IS NULL) OR (Size = ?)) AND ((? = 1 AND Grp IS NULL) OR (Grp = ?)) AND ((? = 1 AND FeedQty IS '.namespace TestMDB
{
public partial class Form1 : Form
{
private OleDbDataAdapter dAdapter;
private DataTable dTable;
private OleDbConnection connection;
private OleDbCommandBuilder cBuilder;
private BindingSource bSource;
private string queryString;
String connectionString;
public Form1()
{
InitializeComponent();
}
static private string GetConnectionString()
{
return @"Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source=D:\Development\C#\TestMDB\TestMDB.mdb;";
}
private void Form1_Load(object sender, EventArgs e)
{
// create the connection string
connectionString = GetConnectionString();
connection = new OleDbConnection(connectionString);
queryString = textBox1.Text;// Select * From tblCalf
// create an OleDbDataAdapter to execute the query
dAdapter = new OleDbDataAdapter(queryString, connection);
// create a command builder
cBuilder = new OleDbCommandBuilder(dAdapter);
// create a datatable to hold query results
dTable = new DataTable();
// fill DataTable
dAdapter.Fill(dTable);
// the DataGridView
//DataGridView dataGridView1 = new DataGridView();
// BindingSource to sync DataTable and DataGridView
bSource = new BindingSource();
// set the BindingSource DataSource
bSource.DataSource = dTable;
// set the DataGridView DataSource
dataGridView1.DataSource = bSource;
// if you don't want to show all columns
//dataGridView1.Columns[0].Visible = false;
//dataGridView1.Columns[2].Visible = false;
}
//update mdb
private void button2_Click(object sender, EventArgs e)
{
dAdapter.Update(dTable);
}Regards Dave
Recent Comments