You are on page 1of 2

using using using using using using using using using using

using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; MySql.Data.MySqlClient; System.IO; System.Data.OleDb;

namespace BioMi.v2 { public partial class insert : Form { string connectionSQL = "server=localhost;database=biomi;uid=root;passwor d=;"; private Kone si sambung; Bitmap gambar u; string alamatGambar u; public insert() { InitializeComponent(); } private void simpan_Clic (object sender, EventArgs e) { File2SqlBlob(alamatGambar u); this.Close(); } private void File2SqlBlob(string SourceFilePath) { try { MySqlConnection cn = new MySqlConnection(connectionSQL); MySqlCommand cmd = new MySqlCommand("INSERT into bio(Foto,No,Nam a,Tgl_lahir,Jenis_Kel,No_Telp,Alamat,Status) values (?Picture," + incrementValue Id() + ",'" + nama.Text + "','" + tgl_lahir.Text + "','" + jenis_ el.SelectedIte m + "','" + no_telp.Text + "','" + alamat.Text + "','" + status.SelectedItem + " '" + ")", cn); System.IO.FileStream fs = new System.IO.FileStream(SourceFilePat h, System.IO.FileMode.Open, System.IO.FileAccess.Read); Byte[] b = new Byte[fs.Length]; fs.Read(b, 0, b.Length); fs.Close(); MySqlParameter P = new MySqlParameter("?Picture", MySqlDbType.Lo ngBlob, b.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Cu rrent, b); cmd.Parameters.Add(P); cn.Open(); if (cmd.ExecuteNonQuery() == 1) MessageBox.Show("Data Berhasil Dimasu an"); cn.Close(); } catch (MySqlException ex) { MessageBox.Show(ex.Message); }

} private int incrementValueId() { try { MySqlConnection db = new MySqlConnection(connectionSQL); db.Open(); MySqlCommand dbcmd = db.CreateCommand(); string sql = "select max(No) from bio"; dbcmd.CommandText = sql; MySqlDataReader reader = dbcmd.ExecuteReader(); while (reader.Read()) { return Convert.ToInt16(reader.GetString(0)) + 1; } return 0; } catch (MySqlException error) { MessageBox.Show(error.ToString()); return 0; } } private void cari_Clic (object sender, EventArgs e) { if (DialogResult.OK == openFileDialog1.ShowDialog()) { gambar u = new Bitmap(openFileDialog1.FileName); pictureBox1.Image = gambar u; alamatGambar u = openFileDialog1.FileName.ToString(); } } private void embali_Clic (object sender, EventArgs e) { this.Hide(); view vw = new view(); vw.ShowDialog(); Application.Exit(); } private void insert_Load(object sender, EventArgs e) { no.Text = incrementValueId().ToString(); } private void hapus_Clic (object sender, EventArgs e) { } } }

You might also like