Datagrid Update

G

Guest

Hi,

I've written a small application that has a serach feature and a datagrid.
It uses an Access database as the backend. I am having difficulties updating
or deleting data through the datagrid. Below is a snippet of the code that I
am using. Can any one tell me what is wrong with the way I am trying to
accomplish this? Possibly point me to an example. Thanks


private void QuerySelect()
{
string ConnectionString =
ConfigurationSettings.AppSettings.Get("ConnStr");
OleDbConnection oConn = new OleDbConnection(ConnectionString);
//OleDbConnection oConn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\DB\\FantasyFootball_DB.mdb");
oDs.Clear();

try
{
strPlayerType = comboBox1.Text;
if(radioButton1.Checked == true)
strQuery = "SELECT [Players], [Team], [Position], [FFPts], [PassYds],
[PassTD], [PassInt]," +
"[PassSack], [RushYds], [RushTD], [RecYds], [RecTD], [RetYds], [RetTD],
[Misc2PT]" +
", [FumLost] FROM PlayersN ORDER BY FFPts DESC";

if(radioButton2.Checked == true)
{
if(comboBox1.Text != "")
strQuery = "SELECT [Players], [Team], [Position], [FFPts],
[PassYds], [PassTD], [PassInt]," +
"[PassSack], [RushYds], [RushTD], [RecYds], [RecTD], [RetYds], [RetTD],
[Misc2PT]," +
"[FumLost] FROM PlayersN WHERE [Position] = " + "'" + strPlayerType + "'"
+ " ORDER BY [FFPts] DESC";
//strQuery = "SELECT * FROM Players WHERE Pos = 'RB'";
}

oDa.SelectCommand = new OleDbCommand(strQuery, oConn);
//DataSet oDs = new DataSet();

oDa.Fill(oDs, "PlayersN");
dataGrid1.SetDataBinding(oDs, "PlayersN");

// DataGridTableStyle tableStyle = dataGrid1.TableStyles["Players"];
// SetColWidth(tableStyle, 1, 200);

//progressBar1.Maximum = _ds.Tables[0].Rows.Count;
//lblDisplay.Text = "Number of Records: " + oDs.Tables[0].Rows.Count;
statusBar1.Text = "Number of Records: " + oDs.Tables[0].Rows.Count;

}

catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}

}

private void btnUpdate_Click(object sender, System.EventArgs e)
{
OleDbCommandBuilder sqlCb = new OleDbCommandBuilder(oDa);
try
{
oDa.Update(oDs, "PlayersN");
MessageBox.Show("Record successfully updated!");
}

catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top