SQLControls Class
public string editContact(Contact contact)
{
string sql = "SELECT * FROM ContactDetails WHERE StudentID = " + contact.studentID;
openConn();
oDa = new SqlDataAdapter(sql, oConn);
oDa.Fill(oDs);
oConn.Close();
try
{
openConn();
string sSql = "UPDATE ContactDetails SET FirstName = '" + contact.fname + "', LastName = '" + contact.lname + "' , ContactNo = '" + contact.cnumber + "'" + " WHERE StudentID ='" + contact.studentID + "'" + ")";
oCmd.CommandText = sSql;
oCmd.Connection = oConn;
oCmd.ExecuteNonQuery();
oConn.Close();
return "Contact was successfully edited!!";
}
catch
{
return "Contact was not successfully edited!!";
}
}
}
Contact Class
class Contact
{
public int studentID;
public string fname;
public string lname;
public string cnumber;
public Contact(int s, string f, string l, string c)
{
studentID = s;
fname = f;
lname = l;
cnumber = c;
}
}
Form
private void btnEdit_Click(object sender, EventArgs e)
{
int sid = int.Parse(tbSID.Text);
String fn = tbFN.Text;
String ln = tbLN.Text;
String cn = tbCon.Text;
Contact edit = new Contact(sid, fn, ln, cn);
SQLControls sc = new SQLControls();
//string msg = sc.addContact(contact);
string msg = sc.editContact(edit);
DialogResult dr = new DialogResult();
dr = MessageBox.Show(msg);
if (dr == DialogResult.OK)
this.Close();
}
}
Thanks!

New Topic/Question
Reply




MultiQuote







|