Estoy haciendo un proyecto en C# (Visual Studio 2008). Y problema es el siguiente: tengo dos formularios y los identificare de la siguiente manera:
Formulario principal donde se muestran todos los resultados.
Formulario de búsqueda.
Lo que necesito hacer es que al introducir el parámetro de búsqueda en el formulario de búsqueda sean mostrados los datos encontrados en la base de datos en el formulario principal.
Si puedo realizar la conexión a la base de datos (la cual esta en SQL Server 2005).
Un ejemplo de cómo lo tengo es el siguiente:
En el formulario de búsqueda esta así (En el cual hay 6 formas de buscar los datos):
- Código: Seleccionar todo
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace wfaInicio
- {
- public partial class FrmBusquedaPropiedad : Form
- {
- public FrmBusquedaPropiedad()
- {
- InitializeComponent();
- }
- private void BtnMostrar_Click(object sender, EventArgs e)
- {
- if (RBPropiedad.Checked.Equals(true))
- {
- if(Propiedad.Text != "")
- {
- VGlobales.VHipotecaPp = Propiedad.Text;
- this.Close();
- }
- else
- {
- MessageBox.Show("Debe introducir un valor para buscar");
- this.Propiedad.Focus();
- }
- }
- else
- {
- if (RBAnotacion.Checked.Equals(true))
- {
- if(Anotacion.Text != "")
- {
- VGlobales.VHipotecaAn = Anotacion.Text;
- this.Close();
- }
- else
- {
- MessageBox.Show("Debe introducir un valor para buscar");
- this.Anotacion.Focus();
- }
- }
- else
- {
- if (RBPresentacion.Checked.Equals(true))
- {
- if (Presentacion.Text != "")
- {
- VGlobales.VHipotecaPr = Presentacion.Text;
- this.Close();
- }
- else
- {
- MessageBox.Show("Debe introducir un valor para buscar");
- this.Presentacion.Focus();
- }
- }
- else
- {
- if (RBCredito.Checked.Equals(true))
- {
- if (Credito.Text != "")
- {
- VGlobales.VHipotecaCr = Credito.Text;
- FrmBusquedaCredito frmBusCre = new FrmBusquedaCredito();
- frmBusCre.WindowState = FormWindowState.Normal;
- frmBusCre.Show();
- this.Close();
- }
- else
- {
- MessageBox.Show("Debe introducir un valor para buscar");
- this.Credito.Focus();
- }
- }
- else
- {
- if (RBInscripcion.Checked.Equals(true))
- {
- if (Inscripcion.Text != "")
- {
- VGlobales.VHipotecaIn = Inscripcion.Text;
- this.Close();
- }
- else
- {
- MessageBox.Show("Debe introducir un valor para buscar");
- this.Inscripcion.Focus();
- }
- }
- else
- {
- if (RBApellido.Checked.Equals(true))
- {
- if (Apellido.Text != "")
- {
- VGlobales.VHipotecaAp = Apellido.Text;
- FrmBusquedaApellido frmBusApe = new FrmBusquedaApellido();
- frmBusApe.WindowState = FormWindowState.Normal;
- frmBusApe.Show();
- this.Close();
- }
- else
- {
- MessageBox.Show("Debe introducir un valor para buscar");
- this.Apellido.Focus();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- public class VGlobales
- {
- public static string VHipotecaPr = null;
- public static string VHipotecaAn = null;
- public static string VHipotecaCr = null;
- public static string VHipotecaAp = null;
- public static string VHipotecaIn = null;
- public static string VHipotecaPp = null;
- }
- }
Y en el formulario principal que todavía no he terminado tengo lo siguiente:
- Código: Seleccionar todo
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace wfaInicio
- {
- public partial class FrmActualizacion : Form
- {
- public FrmActualizacion()
- {
- InitializeComponent();
- }
- private DataTable dt;
- private DataSet ds;
- private SqlDataAdapter da;
- private int fila;
- private SqlConnection con = null;
- private string sCnn = "data source=ITDEV10; Initial catalog=Lalibertad; user id=sa;" +
- "password=123456;";
- private void FrmActualizacion_Load(object sender, EventArgs e)
- {
- if (VGlobales.VHipotecaPp != null)
- {
- try
- {
- con = new SqlConnection(sCnn);
- con.Open();
- SqlDataAdapter da = new SqlDataAdapter(
- "SELECT numfix_s, zoneactiv_n, streetactiv_s, references_s," +
- "description_s FROM fixassets" +
- "WHERE numfix_s ='" + VGlobales.VHipotecaPp + "'", con);
- dt = new DataTable();
- da.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- fila = 0;
- MostrarDatos(fila);
- }
- MessageBox.Show("Conexion establecida");
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error al conectarse a la base de datos:\n" +
- ex.Message, "Conectar con la base", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- finally
- {
- if (con != null)
- {
- con.Close();
- }
- }
- }
- else
- {
- if (VGlobales.VHipotecaAn != null)
- {
- try
- {
- con = new SqlConnection(sCnn);
- con.Open();
- SqlDataAdapter da = new SqlDataAdapter(
- "SELECT fi.numfix_s, fi.zoneactiv_n, fi.streetactiv_s," +
- "fi.references_s, fi.description_s" +
- "FROM fixassets fi LEFT JOIN mortgage mo" +
- "ON fi.numfix_s = mo.numfix_s" +
- "WHERE mo.annot_prev_s ='" + VGlobales.VHipotecaAn + "'", con);
- dt = new DataTable();
- da.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- fila = 0;
- MostrarDatos(fila);
- }
- MessageBox.Show("Conexion establecida");
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error al conectarse a la base de datos:\n" +
- ex.Message, "Conectar con la base", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- finally
- {
- if (con != null)
- {
- con.Close();
- }
- }
- }
- else
- {
- if (VGlobales.VHipotecaPr != null)
- {
- try
- {
- con = new SqlConnection(sCnn);
- con.Open();
- SqlDataAdapter da = new SqlDataAdapter(
- "SELECT fi.numfix_s, fi.zoneactiv_n, fi.streetactiv_s," +
- "fi.references_s, fi.description_s FROM fixassets fi " +
- "LEFT JOIN mortgage mo ON fi.numfix_s = mo.numfix_s" +
- "JOIN mortage_inscription mi ON mo.numfix_s = mi.numfix_s" +
- "WHERE mi.num_pres_s = '" + VGlobales.VHipotecaPr + "'", con);
- dt = new DataTable();
- da.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- fila = 0;
- MostrarDatos(fila);
- }
- MessageBox.Show("Conexion establecida");
- }
- catch (Exception ex)
- {
- MessageBox.Show("Error al conectarse a la base de datos:\n" +
- ex.Message, "Conectar con la base", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- finally
- {
- if (con != null)
- {
- con.Close();
- }
- }
- }
- }
- }
- }
- private void MostrarDatos(int f)
- {
- DataRow dr = dt.Rows[fila];
- Propiedad.Text = dr["numfix_s"].ToString();
- Zona.Text = dr["zoneactiv_n"].ToString();
- Direccion.Text = dr["streetactiv_s"].ToString();
- Referencia.Text = dr["references_s"].ToString();
- Descripcion.Text = dr["description_s"].ToString();
- }
- private void toolStripButton1_Click_1(object sender, EventArgs e)
- {
- FrmBusquedaPropiedad frmBusPro = new FrmBusquedaPropiedad();
- frmBusPro.WindowState = FormWindowState.Normal;
- frmBusPro.Show();
- }
- }
- }
Por lo que solicito su valiosa ayuda de que puedo hacer, que error tengo o que link me recomendarían leer para poder resolver dicho problema. (¿No se si necesitarían que colocara las imágenes de los formularios?).
De antemano muchas gracias por su ayuda y disculpas por perder su tiempo.


