Sei sulla pagina 1di 4

A continuacion se muestra la libreria para hacer un select en informix

using System;
using System.Collections.Generic;
using System.Text;
using IBM.Data.Informix;
using System.Data;
namespace Lib_datos
{
public class producto_ifx
{
public DataSet conproducto(int cdgo_prdcto)
{
DataSet ds = new DataSet();
IfxParameter pcdgo_prdcto = new IfxParameter();
pcdgo_prdcto.IfxType = IfxType.Integer;
pcdgo_prdcto.ParameterName= "@cdgo_prdcto";
pcdgo_prdcto.Direction= ParameterDirection.Input;
pcdgo_prdcto.Value = cdgo_prdcto;
IfxConnection ifxcon = new IfxConnection("Host=marusr; Service=curs
; Server=marusr_shm; Database= mrion ; User Id=as ; Password=3bces; ");
ifxcon.Open();
IfxCommand ifxcomm = new IfxCommand();
ifxcomm.Connection = ifxcon;
ifxcomm.Parameters.Add(pcdgo_prdcto);
ifxcomm.CommandText = " select * from prdcto where cdgo_prdcto =?";
IfxDataAdapter ifxadapter = new IfxDataAdapter(ifxcomm);
try
{
ifxadapter.Fill(ds);
//ifxcomm.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
ifxcon.Close();
}
return ds;
}
}
}
Se invoca desde una forma la clase anterior
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Lib_datos;
namespace clase1
{
public partial class frm_buscar_producto : Form
{
OpenFileDialog objopen = new OpenFileDialog();
public string strimagen;
public frm_buscar_producto()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
producto_ifx obj_prdcto = new producto_ifx();
objopen.Title = "Seleccione el archivo";
objopen.Filter = "text files(*.jpg)|*.jpg";
if (objopen.ShowDialog() == DialogResult.OK)
{
System.IO.FileInfo objinfo = new System.IO.FileInfo(objopen.File
Name);
strimagen = objinfo.Name;
string[] tmp = strimagen.Split('.');
strimagen = tmp[0];
DataSet dsproductos;
dsproductos=obj_prdcto.conproducto(int.Parse(strimagen));
//Aqui se invoca la clase
txt_nmbre.Text = dsproductos.Tables[0].Rows[0]["nmbre_prdcto"].T
oString();
txt_cdgo.Text = dsproductos.Tables[0].Rows[0]["cdgo_prdcto"].ToS
tring();
txt_iva.Text = dsproductos.Tables[0].Rows[0]["iva"].ToString();
}
}
}
}

Asi se abre y se guarda un archivo


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace clase1
{
public partial class frm_dataset : Form
{
OpenFileDialog objopen = new OpenFileDialog();
public string strarchivo;
DataSet ds_infoplano;
public frm_dataset()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
objopen.Title = "Seleccione el archivo";
objopen.Filter = "text files(*.csv)|*.csv";
if (objopen.ShowDialog() == DialogResult.OK)
{
strarchivo = objopen.FileName;
StreamReader objreader = new StreamReader(strarchivo);
//txt_archivo.Text = objreader.ReadToEnd();
objreader.ReadLine();
objreader.ReadLine();
objreader.ReadLine();
ds_infoplano = creardataset(objreader.ReadLine());
while (!objreader.EndOfStream)
{
string[] strdatos = objreader.ReadLine().Split('|');
DataRow dr = ds_infoplano.Tables[0].NewRow();
ds_infoplano.Tables[0].Rows.Add(dr);
dr.ItemArray = strdatos;
/*Remplaza la ins. (int i = 0; i < strdatos.Length; i++)
anterior {
dr[i] = strdatos[i];
}*/
}
dgv_datos.DataSource = ds_infoplano.Tables[0];
objreader.Close();
}
}
private DataSet creardataset(string strcolumnas)
{
DataSet dsplanta = new DataSet("planta");
DataTable dtplanta = new DataTable("tbl_planta");
string[] strcampos = strcolumnas.Split('|');
for (int i = 0; i < strcampos.Length; i++)
{
DataColumn dccolumna = new DataColumn(strcampos[i]);
dtplanta.Columns.Add(dccolumna);
}
dsplanta.Tables.Add(dtplanta);
return dsplanta;
}
private void button2_Click(object sender, EventArgs e)
{
StreamWriter objwrite=new StreamWriter(@"d:\adri\prueba.txt");
int numcol=ds_infoplano.Tables[0].Columns.Count;
foreach (DataRow dr in ds_infoplano.Tables[0].Rows) //recorre las
filas
{
for (int i = 0; i < numcol; i++)
{
objwrite.Write(dr[i].ToString()+"|");
}
objwrite.WriteLine("");
}
objwrite.Close();

ds_infoplano.WriteXml(@"d:\adri\prueba.xml");
}
}
}
Manejar una Fecha
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(dtm_fcha_i.Value.Day.ToString());
MessageBox.Show(dtm_fcha_i.Value.Month.ToString());
MessageBox.Show(dtm_fcha_i.Value.Year.ToString());
}

Potrebbero piacerti anche