I have solve this problem, and this is the code I used. Hope it could help.
public partial class AddDriver : Window
{
MySqlConnection connection = new MySqlConnection();
MySqlDataAdapter adapter = new MySqlDataAdapter();
DatabaseController db = new DatabaseController();
public static string qnum;
public AddDriver()
{
InitializeComponent();
}
private void btn_home_Click(object sender, RoutedEventArgs e)
{
MainWindow main = new MainWindow();
main.Show();
this.Hide();
}
public DataTable driver(string query)
{
DataTable dtable = new DataTable();
try
{
OpenDbase(query);
adapter.Fill(dtable);
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return dtable;
}
private void OpenDbase(string query)
{
try
{
string connectionstring = "server=sql12.freemysqlhosting.net; port=3306; user id=sql12192362; password= DtxpressProject25!; persistsecurityinfo=False;database=sql12192362";
connection = new MySqlConnection(connectionstring);
adapter.SelectCommand = new MySqlCommand(query, connection);
MySqlCommandBuilder cb = new MySqlCommandBuilder(adapter);
connection.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void qrcode_Click(object sender, RoutedEventArgs e)
{
string fn = fnum.Text;
int count = driver("Select * from driver where FranchiseNumber ='" + fn + "'").DefaultView.Count;
if (count > 0)
{
MessageBox.Show("'"+fn+"' is already on the list");
}
else
{
OpenDbase("Insert into driver (LastName, FirstName,MidInitial,Address,Contact,FranchiseNumber,LicenseNumber,Income, Password) values ('" + this.lname.Text + "','" + this.fname.Text + "','" + this.midint.Text + "','" + this.addrss.Text + "','" + this.contact.Text + "','" + this.fnum.Text + "','" + this.lnum.Text + "', '0', '" + this.fnum.Text + "')");
DataTable dtable = new DataTable();
adapter.Fill(dtable);
connection.Close();
}
QRCode qr = new QRCode();
qr.Show();
this.Hide();
qnum = fnum.Text;
}
And this is where I will pass it.
public partial class QRCode : Form
{
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class ArgumentNullException : ArgumentException { }
MySqlConnection connection = new MySqlConnection("server=sql12.freemysqlhosting.net; port=3306; user id=sql12192362; password= DtxpressProject25!; persistsecurityinfo=False;database=sql12192362");
MySqlCommand command;
public QRCode()
{
InitializeComponent();
}
private void btn_gen_Click(object sender, EventArgs e)
{
Zen.Barcode.CodeQrBarcodeDraw qrcode = Zen.Barcode.BarcodeDrawFactory.CodeQr;
pictureBox1.Image = qrcode.Draw(textBox1.Text, 50);
SaveFileDialog f = new SaveFileDialog();
f.Filter = "PNG(*.PNG)|*.png";
if (f.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image.Save(f.FileName);
MessageBox.Show("QR Code has been successfully saved.");
}
}
private void btn_sve_Click(object sender, EventArgs e)
{
MemoryStream ms = new MemoryStream();
byte[] img = ms.ToArray();
string fn = AddDriver.qnum.ToString();
String insertQuery = "Update driver set QrCode = '" + @img + "' where FranchiseNumber= '"+fn+"'";
connection.Open();
command = new MySqlCommand(insertQuery, connection);
command.Parameters.Add("@img", MySqlDbType.Blob);
command.Parameters["@img"].Value = img;
if (command.ExecuteNonQuery() == 1)
{
MessageBox.Show("Driver has been added.");
}
connection.Close();
AddDriver back = new AddDriver();
back.Show();
this.Hide();
}
It's working fine, so far. Also thank you to those who answered.