Thursday, 21 April 2011

How to read and write to a file using c# language?

7 comments:

Munro said...

Bra how do I delete from a database? .mdb? using the SQL methods??

<--Nicky-->

Munro said...

Sorry bra i meant OleDb;

Cubenda said...

I Hope this sintax helps You out!

//Open Connection
ConnectDB();

//Query
string query = "DELETE * FROM TableName WHERE FieldName = '" + ControlName + "'";

Example: string query = "DELETE * FROM Account WHERE [User] = '" + txtUser.Text + "'";
//OleDbDataReader Method
ExecuteQuery(query);

//Close Connection
DisconnectDB();

Munro said...

Bra one more problem..
It seems to delete.. But it will obviously have to overite all data on the actual database if something is added or deleted?? Using the UPDATE(save)..
this is my code but it doesnt seem to work..

ConnectDb();
//Query
string qu = "UPDATE Customer SET [Name] = '" + txt_Name.Text + "', [Surname] = '";
qu = qu + txt_Surname.Text + "',[TelNo] = '";
qu = qu + txt_Telephone.Text + "'";
qu = qu + " WHERE [ID] = '" + lbox_cID.SelectedItem.ToString() + "'";
query(qu);
Disconnect();

it seems confusing but let me know what u think..

Cubenda said...

Try this out (without braces) and debug!

string qu = "UPDATE Customer SET Name = '" + txt_Name.Text + "', Surname = '" + txt_Surname.Text + "', TelNo = '" + txt_Telephone.Text + "' WHERE ID= '" + lbox_CID.SelectedItem.ToString() + "'";
ExecuteQuery(query);
DisconnectDB();

I hope it's useful!!!!

Cubenda said...

Here's a working example:
string query = "UPDATE Account SET Pass = '" + txtPass.Text + "', [Domain] = '" + cmbDomain.SelectedItem.ToString() + "', Name = '" + txtName.Text + "', Surname = '" + txtSurname.Text + "' WHERE [User] = '" + txtUser.Text + "'";
ExecuteQuery(query);
DisconnectDB();

Cubenda said...

Here's a working example:
string query = "UPDATE Account SET Pass = '" + txtPass.Text + "', [Domain] = '" + cmbDomain.SelectedItem.ToString() + "', Name = '" + txtName.Text + "', Surname = '" + txtSurname.Text + "' WHERE [User] = '" + txtUser.Text + "'";
ExecuteQuery(query);
DisconnectDB();

Post a Comment