Simon Green
asked on
c# Update and Delete
Hi All,
Im sure im missing something very simple here but just cant get this working (Newbie im afraid).
I am using the following code:
// Create OLEDB SQL Command String, Create OLEDB DataAdapter then Create Dataset and Fill
// tblUsernames DataAdapter
Static_Database.Static_Dat abase_Obje ct.SETGETS QL = "select * from tblUsernames";
Static_Database.Static_Dat abase_Obje ct.Create_ Command();
oleDbDataAdapterTest = Static_Database.Static_Dat abase_Obje ct.Create_ OleDbDataA dapter();
// REMOVED - datasettest = Static_Database.Static_Dat abase_Obje ct.Create_ DataSet();
// tblDepartments DataAdapter
Static_Database.Static_Dat abase_Obje ct.SETGETS QL = "select * from tblDepartments";
Static_Database.Static_Dat abase_Obje ct.Create_ Command();
oleDbDataAdapter1 = Static_Database.Static_Dat abase_Obje ct.Create_ OleDbDataA dapter();
// tblStatus DataAdapter
Static_Database.Static_Dat abase_Obje ct.SETGETS QL = "select * from tblStatus";
Static_Database.Static_Dat abase_Obje ct.Create_ Command();
oleDbDataAdapter2 = Static_Database.Static_Dat abase_Obje ct.Create_ OleDbDataA dapter();
// Add the DataAdapters into the Dataset
oleDbDataAdapterTest.Fill( datasettes t, "tblUsernames");
oleDbDataAdapter1.Fill(dat asettest, "tblDepartments");
oleDbDataAdapter2.Fill(dat asettest, "tblStatus");
{
if (datasettest.Tables.Count > 0)
{
// Populate Controls
this.Populate_Controls();
}
// Close that Database
Static_Database.Static_Dat abase_Obje ct.CloseDa taBase();
}
}
else if (Static_Database.Static_Da tabase_Obj ect is SQLDB)
{
// Create OLEDB SQL Command String, Create SQL DataAdapter then Create Dataset and Fill
{
if (datasettest.Tables.Count > 0)
{
// Populate Controls
this.Populate_Controls();
}
// Close that Database
Static_Database.Static_Dat abase_Obje ct.CloseDa taBase();
}
}
}
}
// Populate all controls from the DataSet
private void Populate_Controls()
{
lstUsernames.DataSource = datasettest.Tables["tblUse rnames"];
lstUsernames.DisplayMember = "Username";
lstUsernames.ValueMember = "Username";
cboEditDepartment.DataBind ings.Add(" SelectedVa lue", datasettest.Tables[0], "lkDepartment");
cboEditDepartment.DataSour ce = datasettest.Tables["tblDep artments"] ;
cboEditDepartment.DisplayM ember = "Department";
cboEditDepartment.ValueMem ber = "ID";
cboEditStatus.DataBindings .Add("Sele ctedValue" , datasettest.Tables[0], "lkStatus");
cboEditStatus.DataSource = datasettest.Tables["tblSta tus"];
cboEditStatus.DisplayMembe r = "Status";
cboEditStatus.ValueMember = "ID";
txtEditUsername.DataBindin gs.Add("Te xt", datasettest.Tables[0], "Username");
txtEditPassword.DataBindin gs.Add("Te xt", datasettest.Tables[0], "Password");
}
private void btnDelete_Click(object sender, EventArgs e)
{
// OLEDB Delete Here
}
When i run the following command:
private void btnUpdate_Click(object sender, EventArgs e)
{
datasettest.Tables[0].Rows .Add(txtEd itUsername );
datasettest.Tables[1].Rows .Add(txtEd itPassword );
datasettest.Tables[2].Rows .Add(cboEd itDepartme nt);
datasettest.Tables[3].Rows .Add(cboEd itStatus);
datasettest.AcceptChanges( );
}
I get the following error:
Unable to cast object of type 'System.Windows.Forms.Text Box' to type 'System.IConvertible'.Coul dn't store <System.Windows.Forms.Text Box, Text: Simon> in ID Column. Expected type is Int32.
How would I get this to update the database? As i understand .AcceptChanges only effects the Dataset and does not write back to the database?
Cheers Al
Si
Im sure im missing something very simple here but just cant get this working (Newbie im afraid).
I am using the following code:
// Create OLEDB SQL Command String, Create OLEDB DataAdapter then Create Dataset and Fill
// tblUsernames DataAdapter
Static_Database.Static_Dat
Static_Database.Static_Dat
oleDbDataAdapterTest = Static_Database.Static_Dat
// REMOVED - datasettest = Static_Database.Static_Dat
// tblDepartments DataAdapter
Static_Database.Static_Dat
Static_Database.Static_Dat
oleDbDataAdapter1 = Static_Database.Static_Dat
// tblStatus DataAdapter
Static_Database.Static_Dat
Static_Database.Static_Dat
oleDbDataAdapter2 = Static_Database.Static_Dat
// Add the DataAdapters into the Dataset
oleDbDataAdapterTest.Fill(
oleDbDataAdapter1.Fill(dat
oleDbDataAdapter2.Fill(dat
{
if (datasettest.Tables.Count > 0)
{
// Populate Controls
this.Populate_Controls();
}
// Close that Database
Static_Database.Static_Dat
}
}
else if (Static_Database.Static_Da
{
// Create OLEDB SQL Command String, Create SQL DataAdapter then Create Dataset and Fill
{
if (datasettest.Tables.Count > 0)
{
// Populate Controls
this.Populate_Controls();
}
// Close that Database
Static_Database.Static_Dat
}
}
}
}
// Populate all controls from the DataSet
private void Populate_Controls()
{
lstUsernames.DataSource = datasettest.Tables["tblUse
lstUsernames.DisplayMember
lstUsernames.ValueMember = "Username";
cboEditDepartment.DataBind
cboEditDepartment.DataSour
cboEditDepartment.DisplayM
cboEditDepartment.ValueMem
cboEditStatus.DataBindings
cboEditStatus.DataSource = datasettest.Tables["tblSta
cboEditStatus.DisplayMembe
cboEditStatus.ValueMember = "ID";
txtEditUsername.DataBindin
txtEditPassword.DataBindin
}
private void btnDelete_Click(object sender, EventArgs e)
{
// OLEDB Delete Here
}
When i run the following command:
private void btnUpdate_Click(object sender, EventArgs e)
{
datasettest.Tables[0].Rows
datasettest.Tables[1].Rows
datasettest.Tables[2].Rows
datasettest.Tables[3].Rows
datasettest.AcceptChanges(
}
I get the following error:
Unable to cast object of type 'System.Windows.Forms.Text
How would I get this to update the database? As i understand .AcceptChanges only effects the Dataset and does not write back to the database?
Cheers Al
Si
I guess cboEditDepartment is a combo box...
Change it to cboEditDepartment.Selected Item.Text
Thanks,
Rikin
Change it to cboEditDepartment.Selected
Thanks,
Rikin
datasettest.Tables[0].Rows.Add(txtEditUsername);
should be
datasettest.Tables[0].Rows
do the same (append '.Text') to the other textboxes inside btnUpdate_Click event
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi All,
Many thanks for the comments. I have now used:
datasettest.Tables[0].Rows .Add(txtEd itUsername .Text);
datasettest.Tables[1].Rows .Add(txtEd itPassword .Text);
but when trying to run .AcceptChanges it throws up the following Errors:
Input string was not in a correct format.Couldn't store <Test> in ID Column. Expected type is Int32.
Also
datasettest.Tables[2].Rows .Add(cboEd itDepartme nt.Selecte dItem.Text );
datasettest.Tables[3].Rows .Add(cboEd itStatus.S electedIte m.Text);
Reports the follwoing Error:
'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Kusala - What would be a better way to handle the tables? Im a newbie and am only just learning. This basically is what i have done from reading examples, etc.
Cheers Again All
Si
Many thanks for the comments. I have now used:
datasettest.Tables[0].Rows
datasettest.Tables[1].Rows
but when trying to run .AcceptChanges it throws up the following Errors:
Input string was not in a correct format.Couldn't store <Test> in ID Column. Expected type is Int32.
Also
datasettest.Tables[2].Rows
datasettest.Tables[3].Rows
Reports the follwoing Error:
'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Kusala - What would be a better way to handle the tables? Im a newbie and am only just learning. This basically is what i have done from reading examples, etc.
Cheers Again All
Si
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Sudhakar-Pulivarthi,
I have now changed the code to:
datasettest.Tables[1].Rows .Add(txtEd itUsername .Text);
datasettest.Tables[1].Rows .Add(txtEd itPassword .Text);
datasettest.Tables[2].Rows .Add(cboEd itDepartme nt.Selecte dItem);
datasettest.Tables[3].Rows .Add(cboEd itStatus.S electedIte m);
Vut the same message "Input string was not in a correct format.Couldn't store <Test> in ID Column. Expected type is Int32"
Also probably a daft question but how do i tell what is which table? is it the order you populate it?
Cheers
Si
I have now changed the code to:
datasettest.Tables[1].Rows
datasettest.Tables[1].Rows
datasettest.Tables[2].Rows
datasettest.Tables[3].Rows
Vut the same message "Input string was not in a correct format.Couldn't store <Test> in ID Column. Expected type is Int32"
Also probably a daft question but how do i tell what is which table? is it the order you populate it?
Cheers
Si
Yes it is the order we populate the dataset the data tables will be kept. In ur scenario:
datasettest.Tables[0] is tblUsernames
datasettest.Tables[1] is tblDepartments
datasettest.Tables[2] is tblStatus
Hence u have to change as:
datasettest.Tables[0].Rows .Add(txtEd itUsername .Text);
datasettest.Tables[0].Rows .Add(txtEd itPassword .Text);
datasettest.Tables[1].Rows .Add(cboEd itDepartme nt.Selecte dItem);
datasettest.Tables[2].Rows .Add(cboEd itStatus.S electedIte m);
Note: If ur not sure with the table indexes u can use table name instead as:
datasettest.Tables["tblUse rnames"] to avoid confusion in order, usually it happens when ur filling more tables in dataset/ some other dll is providing dataset where we do not know the order.
datasettest.Tables[0] is tblUsernames
datasettest.Tables[1] is tblDepartments
datasettest.Tables[2] is tblStatus
Hence u have to change as:
datasettest.Tables[0].Rows
datasettest.Tables[0].Rows
datasettest.Tables[1].Rows
datasettest.Tables[2].Rows
Note: If ur not sure with the table indexes u can use table name instead as:
datasettest.Tables["tblUse
ASKER
Hi, i think data bindings is causing problem. Pls comment the databindings first and check whether the updation happens with out error. In case u get some probs
Kindly post the sample project and clearly specify what u want to do in the project.
Kindly post the sample project and clearly specify what u want to do in the project.
ASKER
Hi Again Sudhakar-Pulivarthi,
I have commented out the following lines for the Databinding:
txtEditUsername.DataBindin gs.Add("Te xt", datasettest.Tables[0], "Username");
txtEditPassword.DataBindin gs.Add("Te xt", datasettest.Tables[0], "Password");
and it seems to work (or at least not error).
Unfortunatly im using 3rd party controls so the project will not compile without this, so cannot post. Basically though i have a control 2 x Textbox's and 2 a Combos.
Usrrname (Text)
Password (Text)
Status (Combo)
Active (Combo)
These releate to my database which is attached. I just want to be able to edit/update/delete from my control to the database.I have also attached my cose for the control.
Cheers Again
Si
Training.accdb
I have commented out the following lines for the Databinding:
txtEditUsername.DataBindin
txtEditPassword.DataBindin
and it seems to work (or at least not error).
Unfortunatly im using 3rd party controls so the project will not compile without this, so cannot post. Basically though i have a control 2 x Textbox's and 2 a Combos.
Usrrname (Text)
Password (Text)
Status (Combo)
Active (Combo)
These releate to my database which is attached. I just want to be able to edit/update/delete from my control to the database.I have also attached my cose for the control.
Cheers Again
Si
Training.accdb
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
namespace testapp
{
public partial class uctTest : DevExpress.XtraEditors.XtraUserControl
{
public uctTest()
{
InitializeComponent();
}
private void uctTest_Load(object sender, EventArgs e)
{
// Get Company Name and Site fro App.Config
txtCompanyName.Text = ConfigurationSettings.AppSettings["CompanyName"];
txtCompanySite.Text = ConfigurationSettings.AppSettings["CompanySite"];
{
if (Static_Database.Static_Database_Object is OLEDB)
{
// Create OLEDB SQL Command String, Create OLEDB DataAdapter then Create Dataset and Fill
// tblUsernames DataAdapter
Static_Database.Static_Database_Object.SETGETSQL = "select * from tblUsernames";
Static_Database.Static_Database_Object.Create_Command();
oleDbDataAdapterTest = Static_Database.Static_Database_Object.Create_OleDbDataAdapter();
// REMOVED - datasettest = Static_Database.Static_Database_Object.Create_DataSet();
// tblDepartments DataAdapter
Static_Database.Static_Database_Object.SETGETSQL = "select * from tblDepartments";
Static_Database.Static_Database_Object.Create_Command();
oleDbDataAdapter1 = Static_Database.Static_Database_Object.Create_OleDbDataAdapter();
// tblStatus DataAdapter
Static_Database.Static_Database_Object.SETGETSQL = "select * from tblStatus";
Static_Database.Static_Database_Object.Create_Command();
oleDbDataAdapter2 = Static_Database.Static_Database_Object.Create_OleDbDataAdapter();
// Add the DataAdapters into the Dataset
oleDbDataAdapterTest.Fill(datasettest, "tblUsernames");
oleDbDataAdapter1.Fill(datasettest, "tblDepartments");
oleDbDataAdapter2.Fill(datasettest, "tblStatus");
{
if (datasettest.Tables.Count > 0)
{
// Populate Controls
this.Populate_Controls();
}
// Close that Database
Static_Database.Static_Database_Object.CloseDataBase();
}
}
else if (Static_Database.Static_Database_Object is SQLDB)
{
// Create OLEDB SQL Command String, Create SQL DataAdapter then Create Dataset and Fill
{
if (datasettest.Tables.Count > 0)
{
// Populate Controls
this.Populate_Controls();
}
// Close that Database
Static_Database.Static_Database_Object.CloseDataBase();
}
}
}
}
// Populate all controls from the DataSet
private void Populate_Controls()
{
lstUsernames.DataSource = datasettest.Tables["tblUsernames"];
lstUsernames.DisplayMember = "Username";
lstUsernames.ValueMember = "Username";
cboEditDepartment.DataBindings.Add("SelectedValue", datasettest.Tables[0], "lkDepartment");
cboEditDepartment.DataSource = datasettest.Tables["tblDepartments"];
cboEditDepartment.DisplayMember = "Department";
cboEditDepartment.ValueMember = "ID";
cboEditStatus.DataBindings.Add("SelectedValue", datasettest.Tables[0], "lkStatus");
cboEditStatus.DataSource = datasettest.Tables["tblStatus"];
cboEditStatus.DisplayMember = "Status";
cboEditStatus.ValueMember = "ID";
txtEditUsername.DataBindings.Add("Text", datasettest.Tables[0], "Username");
txtEditPassword.DataBindings.Add("Text", datasettest.Tables[0], "Password");
}
private void btnDelete_Click(object sender, EventArgs e)
{
// OLEDB Delete Here
}
private void btnAddUser_Click(object sender, EventArgs e)
{
this.txtEditUsername.Clear();
this.txtEditPassword.Clear();
this.txtEditUsername.Enabled = true;
this.txtEditPassword.Enabled = true;
this.cboEditDepartment.Enabled = true;
this.cboEditStatus.Enabled = true;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
datasettest.Tables[1].Rows.Add(txtEditUsername.Text);
datasettest.Tables[1].Rows.Add(txtEditPassword.Text);
datasettest.Tables[2].Rows.Add(cboEditDepartment.SelectedItem);
datasettest.Tables[3].Rows.Add(cboEditStatus.SelectedItem);
datasettest.AcceptChanges();
}
// Enable Controls ready for Editing
private void btnEdit_Click(object sender, EventArgs e)
{
this.txtEditUsername.Enabled = true;
this.txtEditPassword.Enabled = true;
this.cboEditDepartment.Enabled = true;
this.cboEditStatus.Enabled = true;
}
// Mouse Click for Control Colours
private void Generic_MouseClick(object sender, MouseEventArgs e)
{
((Control)sender).BackColor = Color.LightBlue;
}
// Key Down for Control Colours
private void Generic_KeyDown(object sender, KeyEventArgs e)
{
((Control)sender).BackColor = Color.LightBlue;
}
}
}
hi
I did not test your code, so by just looking;
Do you always used [0]?, I think it's [2] for department and [3] for status.
I think your repeating the table orders?
cboEditDepartment.DataBind ings.Add(" SelectedVa lue", datasettest.Tables[0], "lkDepartment");
...
...
...
cboEditStatus.DataBindings .Add("Sele ctedValue" , datasettest.Tables[0], "lkStatus");
...
...
...
Just my sight;
I think, that's one of the errors you should look out.
Sorry if I got it wrong, but that's the way I see it. You initialized the index wrong.
You can also try to change
from selecteditem to selectedText or selecteditem.toString
I did not test your code, so by just looking;
Do you always used [0]?, I think it's [2] for department and [3] for status.
I think your repeating the table orders?
cboEditDepartment.DataBind
...
...
...
cboEditStatus.DataBindings
...
...
...
Just my sight;
I think, that's one of the errors you should look out.
Sorry if I got it wrong, but that's the way I see it. You initialized the index wrong.
You can also try to change
from selecteditem to selectedText or selecteditem.toString
ASKER
Hi Systan,
I have tried changing the above but to no avail. I think i should be using [0] as lkDepartment is a table within the username table (Which looks up another table - Deparmtents).
Im pretty sure this is something simple i just can figure out what. Doing a lot of reading last night im thinking it maybe and issue with the primary key, but i have checked the Database and it has a PrimaryKey set.
Cheers
Si
I have tried changing the above but to no avail. I think i should be using [0] as lkDepartment is a table within the username table (Which looks up another table - Deparmtents).
Im pretty sure this is something simple i just can figure out what. Doing a lot of reading last night im thinking it maybe and issue with the primary key, but i have checked the Database and it has a PrimaryKey set.
Cheers
Si
ASKER
Hi Again All,
I have just renamed the primary Key olum or testing. Im deffinatly sure its something to do with this now as i get the following error:
Input string was not in a correct format.Couldn't store <gfdsgfsd> in Usernames_ID Column. Expected type is Int32
Usernames_ID Colum is indeed the Primary Key Column of the USernames Table. gfdsgfsd what what i typed in the Username textbox.
Why is it trying to save this in the Primary Key Colum in the database? It should be added to the Username Column in the database?
Cheers
Si
I have just renamed the primary Key olum or testing. Im deffinatly sure its something to do with this now as i get the following error:
Input string was not in a correct format.Couldn't store <gfdsgfsd> in Usernames_ID Column. Expected type is Int32
Usernames_ID Colum is indeed the Primary Key Column of the USernames Table. gfdsgfsd what what i typed in the Username textbox.
Why is it trying to save this in the Primary Key Colum in the database? It should be added to the Username Column in the database?
Cheers
Si
Hi Simon,
Instead of providing the select * command specify the columns you want to use from the tables like
select username,password from tblUsernames
When u provide select * ur ID columns are also used in databinding process.
Instead of providing the select * command specify the columns you want to use from the tables like
select username,password from tblUsernames
When u provide select * ur ID columns are also used in databinding process.
ASKER
Hi Sudhakar-Pulivarthi,
Many thanks for that - im getting much closed now:) Its adding to the Dataset now .... However (As nothing is Easy), its complain about:
"Input string was not in a correct format.Couldn't store <gfdsgfsd> in Usernames_ID Column. Expected type is Int32"
For bothe the Department and the Status Column, but i need these as the ComboBox usesthese as it value memeber:
cboEditDepartment.DataBind ings.Add(" SelectedVa lue", datasettest.Tables[0], "lkDepartment");
cboEditDepartment.DataSour ce = datasettest.Tables["tblDep artments"] ;
cboEditDepartment.DisplayM ember = "Department";
cboEditDepartment.ValueMem ber = "ID";
Also i notice when i call datasettest.AcceptChanges( ); it ass 3 x Copies of the Data? I.E I add Roger as a Username and call datasettest.AcceptChanges( ); when i look in the Listsbox Roger is there 3 times?
Cheers again and many thanks for all your help so far.
Si
Many thanks for that - im getting much closed now:) Its adding to the Dataset now .... However (As nothing is Easy), its complain about:
"Input string was not in a correct format.Couldn't store <gfdsgfsd> in Usernames_ID Column. Expected type is Int32"
For bothe the Department and the Status Column, but i need these as the ComboBox usesthese as it value memeber:
cboEditDepartment.DataBind
cboEditDepartment.DataSour
cboEditDepartment.DisplayM
cboEditDepartment.ValueMem
Also i notice when i call datasettest.AcceptChanges(
Cheers again and many thanks for all your help so far.
Si
Hi Simon,
There is one more change need to be made! Usually when we bind with adapters, INSERT, UPDATE and DELETE commands are generated automatically. Which again works in generic trying to work on all columns. causing problems. Hence write these commands to be used by adapter to perform it.
Refer here for more help and info om these topic.
http://www.akadia.com/services/dotnet_update_form.html
There is one more change need to be made! Usually when we bind with adapters, INSERT, UPDATE and DELETE commands are generated automatically. Which again works in generic trying to work on all columns. causing problems. Hence write these commands to be used by adapter to perform it.
Refer here for more help and info om these topic.
http://www.akadia.com/services/dotnet_update_form.html
ASKER
Hi again Sudhakar-Pulivarthi,
OK i have read the following but even more confused now .... To simplify things i have created a new "simple Project" with my code in and have put it for download here: http://www.network-db.co.uk/files/TestApp.zip. I have also attached my database to here.
I'm just so stuck on Deleting, Updating/Adding. What i though would be fairly simple is proving very difficult to get working:(
Any code you could help me out with would be awsome.
Cheers Again
Si
Training.accdb
OK i have read the following but even more confused now .... To simplify things i have created a new "simple Project" with my code in and have put it for download here: http://www.network-db.co.uk/files/TestApp.zip. I have also attached my database to here.
I'm just so stuck on Deleting, Updating/Adding. What i though would be fairly simple is proving very difficult to get working:(
Any code you could help me out with would be awsome.
Cheers Again
Si
Training.accdb
Hi Simon,
Pls use this code for btnUpdate_Click event and check. It is adding properly to the grid and no redundant is found.
Let me know is this ur requirement was..
Pls use this code for btnUpdate_Click event and check. It is adding properly to the grid and no redundant is found.
Let me know is this ur requirement was..
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
datasettest.Tables[0].Rows.Add(txtEditUsername.Text, txtEditPassword.Text, ((DataRowView)cboEditDepartment.SelectedItem)[0], ((DataRowView)cboEditStatus.SelectedItem)[0]);
datasettest.AcceptChanges();
this.txtEditUsername.Enabled = false;
this.txtEditPassword.Enabled = false;
this.cboEditDepartment.Enabled = false;
this.cboEditStatus.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Sudhakar-Pulivarthi,
Excellent - thats doing just what i wanted:) only 1 more question, well 2 if i May?
1st - How do i get it to delete rowns? and
2nd - How do i get the dataset updates to go back to that database?
Many thanks again for your valued time and help
Si
Excellent - thats doing just what i wanted:) only 1 more question, well 2 if i May?
1st - How do i get it to delete rowns? and
2nd - How do i get the dataset updates to go back to that database?
Many thanks again for your valued time and help
Si
Hi Simon,
This is the code for delete event.
private void btnDelete_Click(object sender, EventArgs e)
{
// Check whether any users sre present in the table.
if (datasettest.Tables[0].Row s.Count > 0)
{
// Create the filter to obtain the record from the tblusernames table in dataset
StringBuilder selectFilter = new StringBuilder();
selectFilter.Append("[User name] = '").Append(txtEditUsername .Text).App end("' AND ");
selectFilter.Append("[Pass word] = '").Append(txtEditPassword .Text).App end("' AND ");
selectFilter.Append("[lkDe partment] = '").Append(((DataRowView)c boEditDepa rtment.Sel ectedItem) [0]).Appen d("' AND ");
selectFilter.Append("[lkSt atus] = '").Append(((DataRowView)c boEditStat us.Selecte dItem)[0]) .Append("' ");
// Get the required record from the tblusernames
DataRow[] detailsRows = datasettest.Tables[0].Sele ct(selectF ilter.ToSt ring());
if (detailsRows.Length > 0)
{
// Remove the record.
datasettest.Tables[0].Rows .Remove(de tailsRows[ 0]);
}
}
}
To update the data back to database as i said above we need to implement the INSERT,UPDATE, DELETE command on the adapter as in the link i have provided.
This is the code for delete event.
private void btnDelete_Click(object sender, EventArgs e)
{
// Check whether any users sre present in the table.
if (datasettest.Tables[0].Row
{
// Create the filter to obtain the record from the tblusernames table in dataset
StringBuilder selectFilter = new StringBuilder();
selectFilter.Append("[User
selectFilter.Append("[Pass
selectFilter.Append("[lkDe
selectFilter.Append("[lkSt
// Get the required record from the tblusernames
DataRow[] detailsRows = datasettest.Tables[0].Sele
if (detailsRows.Length > 0)
{
// Remove the record.
datasettest.Tables[0].Rows
}
}
}
To update the data back to database as i said above we need to implement the INSERT,UPDATE, DELETE command on the adapter as in the link i have provided.
ASKER
Hi Sudhakar-Pulivarthi:,
As sorry was one of the originalproblems. I didnt understand what to do even after reading the like (several times now) :(
Cheers
Si
As sorry was one of the originalproblems. I didnt understand what to do even after reading the like (several times now) :(
Cheers
Si
This code is really different, it looks wild and dirty.
Anyway there are many ways to kill a cat.
How's this?, is it solved?
Anyway there are many ways to kill a cat.
How's this?, is it solved?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Everyone,
Thanks again for all you help. and deffinatly thanks to Sudhakar-Pulivarthi for sticking with this thread:).
It certainly has been a weekend of reading.
Kusala, Just what i was after for the DB Update.
Im actually starting to understand whats going on now (I think) and have a good reference to go off. How do i delete and update using the new code above from Kusala.
I am actually finding it very hard to find any simple DB example for C# on the internet they all seem to VB.Net.
Cheers Again Everyone
Si
Thanks again for all you help. and deffinatly thanks to Sudhakar-Pulivarthi for sticking with this thread:).
It certainly has been a weekend of reading.
Kusala, Just what i was after for the DB Update.
Im actually starting to understand whats going on now (I think) and have a good reference to go off. How do i delete and update using the new code above from Kusala.
I am actually finding it very hard to find any simple DB example for C# on the internet they all seem to VB.Net.
Cheers Again Everyone
Si
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for helping me on this one everyone:)
Thanks,
Rikin