check on this example I did with insert statement and the advice me accordingly:
this code is for entering a new farmer.it's in the DBConnect.cs that has the database connection string
//Insert statement
public bool newFarmer(string accountNum, string fname, string lname, string othnames, string loca, string SizeOfFarm, string owner, string regfee, string DateOFReg)
{
string query = "INSERT INTO farmer (account_no,firstname,lastname,othernames,location,size,ownership,registration_fee,date) VALUES('" + accountNum + "','" + fname + "','" + lname + "','" + othnames + "','" + loca + "','" + SizeOfFarm + "','" + owner + "','" + regfee + "','" + DateOFReg + "')";
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
if (cmd.ExecuteNonQuery() > 0)
{
//close connection
this.CloseConnection();
return true;
}
else
return false;
}
else
return false;
}
and then in the form that I enter the farmer details I have this:
private void buttonSave_Click_1(object sender, EventArgs e)
{
DBConnection db = new DBConnection();
accNum = textBoxAccNum.Text.Trim();
fname = textBFirstName.Text.Trim();
lname = textLastName.Text.Trim();
oname = txtBxOtherName.Text.Trim();
loc = textBoxLocation.Text.Trim();
sizeOFfarm = textBoSize.Text.Trim();
own = comboBox1.SelectedItem.ToString();
regFee = txtBxRegFee.Text.Trim();
DateOfReg = datTimPickRegDate.Value.ToShortDateString();
String[] dateArr = DateOfReg.Split('/');
Array.Reverse(dateArr);
DateOfReg = String.Join("-", dateArr);
if (db.newFarmer(textBoxAccNum.Text, textBFirstName.Text, textLastName.Text, txtBxOtherName.Text, textBoxLocation.Text, textBoSize.Text, comboBox1.SelectedItem.ToString(), txtBxRegFee.Text, DateOfReg))
{
MessageBox.Show("Farmer Added Successfully.");
reset();
}
else
MessageBox.Show("Could Not Add Farmer");
}
how do you now go about with one that takes values from database,allows you to edit and send the values back to the database?