Bienvenidos!!!

Espero que este pequeño espacio ayude a solucionar problemas y aclarar dudas.

" El Exito no debe medirse por la posicion a que una persona ha llegado, sino po su esfuerzo por triunfar ".







viernes, 26 de noviembre de 2010

Programacion c# String Conexion SQL Server2005

  //validacion y ingreso y actualizacion
SqlConnection conn = new SqlConnection("Data Source=ALEXIS-PC;Initial Catalog=ERP;Persist Security Info=True;User ID=sa;Password=rsc9sra2");
conn.Open();// abro conexion.
 string StrComando = "SELECT * FROM MAEPR WHERE KOPRTE='" + txt_tecnico.Text + "'";
SqlCommand COMAND = new SqlCommand(StrComando, conn);
DataTable tabla = new DataTable(); // El resultado lo guardaremos en una tabla
SqlDataAdapter AdaptadorTabla = new SqlDataAdapter(StrComando, conn); // Usaremos un DataAdapter para leer los datos

 AdaptadorTabla.Fill(tabla);
 if (tabla.Rows.Count == 0)
     {}

Obtener el Digito Verificador del Rut. Formula

 

------- Preguntas Varias -------

Llenar datos a Datagridview

Leer mas..... 

Manera Sencilla de llenar los textBox desde Base de datos

//conexion a base de datos
SqlConnection conn = new SqlConnection("Data Source=ALEXIS-PC;Initial Catalog=ERP;Persist Security Info=True;User ID=sa;Password=rsc9sra2");
conn.Open();// abro conexion.
string StrComando = "SELECT * FROM MAEPR WHERE KOPRTE='" + txt_tecnico.Text + "'";
SqlCommand COMAND = new SqlCommand(StrComando, conn);
DataTable tabla = new DataTable(); // El resultado lo guardaremos en una tabla
SqlDataAdapter AdaptadorTabla = new SqlDataAdapter(StrComando, conn); // Usaremos un DataAdapter para leer los datos
//DataSet ds = new DataSet();
AdaptadorTabla.Fill(tabla);// Llenamos la tabla con los datos leídos



string kopr = tabla.Rows[0]["KOPR"].ToString();//guardo informacion en variables
string nokopr = tabla.Rows[0]["NOKOPR"].ToString();
string ud1 = tabla.Rows[0]["UD1"].ToString();
string ud2 = tabla.Rows[0]["UD2"].ToString();
string rlud = tabla.Rows[0]["RLUD"].ToString();
string estado = tabla.Rows[0]["ESTPR"].ToString();
string ex = tabla.Rows[0]["EXEPR"].ToString();
string iva = tabla.Rows[0]["IVA"].ToString();
string tipo = tabla.Rows[0]["TIPR"].ToString();



txt_principal.Text = kopr;//asigno valores a txt
txt_descripcion.Text = nokopr;
txt_ud1.Text = ud1;
txt_ud2.Text = ud2;
txt_rtu.Text = rlud;
txt_iva.Text = iva;
cb_estado.Text = estado;

String de Conexion a base de Datos Acces C#

using System.Data.OleDb;
****

OleDbConnection Conexion;//objeto para efectuar la conexion
Conexion = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:.\\..\\..\\Bigotes.mdb");
Conexion.Open();
String consulta = "SELECT * FROM Mascotas";                              

OleDbCommand ORDEN;      
ORDEN = new OleDbCommand(consulta, Conexion);
OleDbDataAdapter AdaptadorTabla = new OleDbDataAdapter(consulta, Conexion);
DataTable tabla = new DataTable();
AdaptadorTabla.Fill(tabla);
if (tabla.Rows.Count == 0)
  {
 MessageBox.Show("0 filas");

  }
else { MessageBox.Show("exito"); }

Conexion.Close();

String de Conexion a base de Datos Acces

using System.Data.OleDb;
****

OleDbConnection Conexion;//objeto para efectuar la conexion
Conexion = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:.\\..\\..\\Bigotes.mdb");
Conexion.Open();
String consulta = "SELECT * FROM Mascotas";                              

OleDbCommand ORDEN;      
ORDEN = new OleDbCommand(consulta, Conexion);
OleDbDataAdapter AdaptadorTabla = new OleDbDataAdapter(consulta, Conexion);
DataTable tabla = new DataTable();
AdaptadorTabla.Fill(tabla);
if (tabla.Rows.Count == 0)
  {
 MessageBox.Show("0 filas");

  }
else { MessageBox.Show("exito"); }

Conexion.Close();

Repaso Consultas SQL

sintaxis SQL para CREATE TABLE:
CREATE TABLE "nombre_tabla"
("columna 1" "tipo_de_datos_para_columna_1",
"columna 2" "tipo_de_datos_para_columna_2",
... )
Entonces, si debemos crear una tabla para el cliente tal como se especifica anteriormente, ingresaríamos
CREATE TABLE personal
(Nombre char(50),
Apellido char(50),
Direccion char(50),
Comuna(50),
Ciudad(25),
Fechanacimiento date)
 

*******************************************************************************************************
 INSERT INTO "nombre_tabla" ("columna1", "columna2", ...)VALUES ("valor1", "valor2", ...)
INSERT INTO personal (nombre, apellido, dirección)
VALUES ('Alexis', 'Bataller', 'duoc')
*****************************************************************************************************
UPDATE "nombre_tabla"
SET colonne 1 = [[valor1], colonne 2 = [valor2]
WHERE {condición}
UPDATE personal
SET nombre = alexis
WHERE rut = "15533111-1"
*****************************************************************************************************
DELETE FROM Nombre_Tabla
WHERE {condición}
DELETE FROM personal
WHERE rut = "15533111-1"
***************************************************************************************************


Si quiero unir 2 tablas por ejemplo:
personal y prestamos que tienen en común el Rut se aria lo siguiente:

select rut, nombre, valor prestamo
from personal inner join prestamo on personal.rut= prestamo.rut
where rut='15533111-1'