public void probarConexion() { using (DataAccess.Conexion con = new DataAccess.Conexion()) { SqlConnection c = con.getConexion(); } }
public void guardarFoto(object sender, EventArgs e) { using (DataAccess.Conexion con = new DataAccess.Conexion()) { SqlConnection c = con.getConexion(); string query = "INSERT INTO imagen (IMG) VALUES(@imagenWeb)"; try { String base64 = this.HiddenField1.Value; //base64.Replace("\"", ""); String p1 = base64.Replace("data:image/png;base64,", String.Empty); byte[] pr1 = Convert.FromBase64String(p1); //byte[] imagenInBytes = Convert.FromBase64String(this.HiddenField1.Value.ToString()); //byte[] a = File.ReadAllBytes(@"C:\Users\Administrador\Downloads\CapturaImagen (54).png"); SqlCommand comando = new SqlCommand(query, c); //comando.Parameters.AddWithValue("@imagen", FileUpload1.FileBytes); comando.Parameters.AddWithValue("@imagenWeb", pr1); comando.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
private void button2_Click(object sender, EventArgs e) { if (camara != null && camara.IsRunning) { pictureBox1.Image = imagen.Image; //pictureBox1.Image.Save(path + "imagen.jpg", ImageFormat.Jpeg); DataAccess.Conexion c = new DataAccess.Conexion(); c.getConexion(); } }
public bool guardarFoto() { using (DataAccess.Conexion con = new DataAccess.Conexion()) { SqlConnection c = con.getConexion(); string query = "INSERT INTO imagen (IMG) VALUES(@imagen)"; try { SqlCommand comando = new SqlCommand(query, c); } catch (Exception ex) { } } return(false); }
private void imagen_Load(object sender, EventArgs e) { DataAccess.Conexion con = new DataAccess.Conexion(); String query = "SELECT IMG FROM imagen ORDER BY ID DESC"; SqlConnection c = con.getConexion(); SqlCommand comand = new SqlCommand(query, c); SqlDataAdapter dp = new SqlDataAdapter(comand); DataSet datos = new DataSet("IMG"); byte[] imagen = new byte[0]; dp.Fill(datos, "IMG"); DataRow linea = datos.Tables["IMG"].Rows[0]; imagen = (byte[])linea["IMG"]; MemoryStream ms = new MemoryStream(imagen); this.pictureBox1.Image = Image.FromStream(ms); }
private void button3_Click(object sender, EventArgs e) { DataAccess.Conexion con = new DataAccess.Conexion(); SqlConnection c = con.getConexion(); String query = "INSERT INTO imagen(IMG) VALUES(@imagen)"; try { // Image img = this.pictureBox1.Image; byte[] img = imagenToArray(this.pictureBox1.Image); SqlCommand comando = new SqlCommand(query, c); comando.Parameters.AddWithValue("@imagen", img); comando.ExecuteNonQuery(); MessageBox.Show("Guardado en la DB"); } catch (Exception ex) { MessageBox.Show("Error"); MessageBox.Show(ex.ToString()); } }
public void mostrarUltimaImagen(object sender, EventArgs e) { using (DataAccess.Conexion con = new DataAccess.Conexion()) { SqlConnection c = con.getConexion(); string query = "SELECT imagen FROM imagen ORDER BY ID DESC"; //string query = "SELECT IMG FROM imagen ORDER BY ID DESC"; try { SqlCommand comando = new SqlCommand(query, c); SqlDataReader lector = comando.ExecuteReader(); if (lector.Read()) { this.dbImage.Src = lector["imagen"].ToString(); //this.dbImage.Src = lector["imagen"].ToString(); } } catch (Exception ex) { } } }
public bool conectar(String user, String password) { SqlConnection c = con.getConexion(); //venUsuario venContraseña String sql = "SELECT * FROM dbo.vendedores WHERE venUsuario = @user AND venContraseña = @pass"; try { SqlCommand comando = new SqlCommand(sql, c); comando.Parameters.AddWithValue("@user", user); comando.Parameters.AddWithValue("@pass", password); SqlDataReader lector = comando.ExecuteReader(); if (lector.Read()) { String userDb = lector.GetValue(0).ToString(); String passDb = lector.GetValue(1).ToString(); if (user.Equals(userDb) && password.Equals(passDb)) { return(true); } } }catch (Exception ex) { Console.WriteLine("Usuario NO encontrado"); return(false); } finally { c.Close(); } return(false); }