elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Temas
Páginas: [1]
1  Programación / .NET (C#, VB.NET, ASP) / Conexion Sql Express con programa hecho en C# en: 9 Diciembre 2009, 03:05 am
Saludos amigos..
Pues veran hoy en la universidad me encargaron hacer un proyecto en C# y en modo ventanas, tambien crear una base de datos en Sql y esta misma conectarla a C#. Ya tengo todo creado el programa en C# y la base de datos creada en Sql, ya la conecte, pero me sale un pequeño error el cual no se como arreglar.


Si alguien me puede ayudar a solucionar mi problemita estare muy agradecido.

Chequen el dato, el codigo del programa junto para conectar con la base es el siguiente

Código:
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 baseproyecto
{
    public partial class Form1 : Form
    {
        public String conStr = "Data Source=.\\Sqlexpress; Initial Catalog=video;Integrated Security=true";
        public SqlConnection myCon = new SqlConnection();
        public SqlCommand myComm = new SqlCommand();
        public SqlDataAdapter myAdapter = new SqlDataAdapter();
        public String nombre, telefono, correo,direccion,ciudad;
        public int ID, i;
       

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ID = int.Parse(textBox1.Text);
            myCon.ConnectionString = conStr;
            myComm.CommandText = "Select nombre,telefono,correo,direccion,ciudad From cliente Where id_cliente ='" + ID + "' ";
            myComm.Connection = myCon;
            myAdapter.SelectCommand = myComm;
            DataSet myds = new DataSet();
            int numrows = myAdapter.Fill(myds, "video");
            if (numrows > 0)
            {
                textBox2.Text = myds.Tables["cliente"].Rows[0]["nombre"].ToString();
                textBox3.Text = myds.Tables["cliente"].Rows[0]["telefono"].ToString();
                textBox4.Text = myds.Tables["cliente"].Rows[0]["correo"].ToString();
                textBox5.Text = myds.Tables["cliente"].Rows[0]["direccion"].ToString();
                textBox6.Text = myds.Tables["cliente"].Rows[0]["ciudad"].ToString();
            }
            myCon.Close();
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //creamos el objeto de la conexion
            SqlConnection mycon = new SqlConnection();
            //asignamos la cadena de la conexion
            mycon.ConnectionString = "Data source=.\\SqlExpress;initial catalog=video;" + "integrated security=true";
            //creamos un objeto de tipo comando
            SqlCommand mycommand = new SqlCommand();
            //asignamos consulta
            mycommand.CommandText = "select*from cliente";
            //conectamos el comando con la conexion a la base de datos
            mycommand.Connection = mycon;
            //creamos el adaptador para traer informacion de la base de datos
            SqlDataAdapter myAdapter = new SqlDataAdapter();
            myAdapter.SelectCommand = mycommand;
            //creamos un dataset para crear una imagen de la base de datos
            DataSet myds = new DataSet();
            //rellenamos el adaptador con la tabla a utilizar
            myAdapter.Fill(myds,"video");
            dataGridView1.DataSource = myds;
            dataGridView1.DataMember = "video";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ID = int.Parse(textBox1.Text);
            nombre = textBox2.Text;
            telefono = textBox3.Text;
            correo = textBox4.Text;
            direccion = textBox5.Text;
            ciudad = textBox6.Text;
            myCon.ConnectionString = conStr;
            myComm.CommandText = "UPDATE cliente SET Nombre='" + nombre + "',Telefono='" + telefono + "',"
                                 + "correo='" + correo + "',direccion='" + direccion+ "',ciudad='"+ciudad+" 'WHERE Id_cliente= '" + ID + "'";
            myComm.Connection = myCon;
            myCon.Open();
            i= myComm.ExecuteNonQuery();
            myCon.Close();
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string ConStr;
            int ID;
            ID = int.Parse(textBox1.Text);
            ConStr = "Data Source =.\\Sqlexpress; Initial catalog=video; integrated security=true";
                SqlConnection mycon=new SqlConnection();
            mycon.ConnectionString=ConStr;
            SqlCommand mycommand=new SqlCommand();
            mycommand.CommandText="Delete from cliente where id_cliente='" +ID+ " '";
            mycommand.Connection=mycon;
            mycon.Open();
            int i=mycommand.ExecuteNonQuery();
            mycon.Close();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            nombre = textBox2.Text;
            telefono = textBox5.Text;
            correo = textBox4.Text;
            direccion = textBox3.Text;
            ciudad = textBox6.Text;
            myCon.ConnectionString = conStr;
            myComm.CommandText = "INSERT INTO cliente(Nombre,Telefono,correo,direccion,ciudad)"
            + " VALUES (' " + nombre + " ',' " + telefono + " ',' " + correo + " ','" + direccion + " ',' " + ciudad + " ')";
            myComm.Connection = myCon;
            myCon.Open();
            i = myComm.ExecuteNonQuery();
            myCon.Close();
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void but_cargar_Click(object sender, EventArgs e)
        {
            myCon.ConnectionString = conStr;
            myComm.CommandText = "Select * From cliente";
            myComm.Connection = myCon;
            myAdapter.SelectCommand = myComm;
            DataSet myds = new DataSet();
            myAdapter.Fill(myds, "cliente");
            dataGridView1.DataSource = myds;
            dataGridView1.DataMember = "cliente";

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            ID = int.Parse(textBox1.Text);
            myCon.ConnectionString = conStr;
            myComm.CommandText = "Select nombre,direccion,telefono,correo,ciudad From cliente Where id_cliente ='" + ID + "'";
            myComm.Connection = myCon;
            myAdapter.SelectCommand = myComm;
            DataSet myds = new DataSet();
            int numrows = myAdapter.Fill(myds, "cliente");
            if (numrows > 0)
            {
                textBox2.Text = myds.Tables["cliente"].Rows[0]["nombre"].ToString();
                textBox3.Text = myds.Tables["cliente"].Rows[0]["direccion"].ToString();
                textBox4.Text = myds.Tables["cliente"].Rows[0]["telefono"].ToString();
                textBox5.Text = myds.Tables["cliente"].Rows[0]["correo"].ToString();
                textBox6.Text = myds.Tables["cliente"].Rows[0]["ciudad"].ToString();
            }
            myCon.Close();

        }

       
    }
}

Script de la base:

Código:
create database video
create table dbo.cliente(
id_cliente int primary key not null identity,
nombre nvarchar (50)not null,
direccion nvarchar (50)not null,
telefono nchar (15)not null,
correo nvarchar (50)not null,
ciudad nvarchar (50)not null)

create table dbo.pelicula(
id_pelicula int primary key not null,
nombre nvarchar(50)not null,
clasificacion nvarchar(50)not null)

create table dbo.renta(
id_cliente int not null,
id_pelicula int not null,
fecha_renta smalldatetime not null)

create table dbo.entrega(
id_cliente int not null,
id_pelicula int not null,
fecha_entrega smalldatetime not null)

create table dbo. descuentos(
id_descuento int primary key not null,
id_cliente int not null,
tipo_descuento nvarchar(50) not null)


insert into cliente values ('Manuel Gutierrez Frescas','calle carrizal del norte #5346','6142178599','menny@hotmail.com','chihuahua')
insert into cliente values ('Vianney Dominguez Acevedo','portugal#5786','6144205746','vyda_@hotmail.com','chihuahua')
insert into cliente values ('Rosa Maria Zaragoza Chacon','Hacienda del Rey','6142190832','ch@hotmail.com','chihuahua')
insert into cliente values ('Perla Siqueiros Gracia','Calle Tepochcalli #6238','6144340647','perlisky@hotmail','Chihuahua')
insert into cliente values ('Janeth Grano Mendoza','Calle de la Rosa #5531','6144194563','lajaneth@hotmail.com','chihuahua')
 select *from cliente
insert into pelicula values('8234','Luna Nueva','Terror')
insert into pelicula values ('5467','Monster Inc','Infantil')
insert into pelicula values ('9516','chucky','Terror')
insert into pelicula values ('1426','Diario de una pasion','Romance')
insert into pelicula values ('0999','lluvia de Hamburguesas','Infantil')
select*from pelicula
insert into renta values ('2','9516','9-12-09')
insert into renta values ('5','8234','11-12-09')
insert into renta values ('1','1426','12-12-09')
insert into renta values ('3','5467','15-12-09')
insert into renta values ('4','0999','17-12-09')

select*from renta

insert into entrega values ('2','9516','11-12-09')
insert into entrega values ('5','8234','13-12-09')
insert into entrega values ('3','1426','15-12-09')
insert into entrega values ('4','5467','17-12-09')
insert into entrega values ('1','0999','19-12-09')
select * from entrega

insert into descuentos values ('555','3','25%')
insert into descuentos values ('267','2','15%')
insert into descuentos values ('333','1','20%')
insert into descuentos values ('231','4','5%')
insert into descuentos values ('429','5','30%')

PD: Cada uno de esos datos los invente.

Ahora cuando intento correr el programa me tira un mensaje el cual dice No se controlo SqlException y El nombre de objeto 'cliente' no es válido.,

Y obviamente el programa no corre.
Que podre hacer o que tengo que hacer para solucionar ese problemilla.

Saludos
2  Seguridad Informática / Nivel Web / Foro privado? en: 3 Noviembre 2009, 02:21 am
Me han dicho que eso es posible entrar  utilizando un proxy, es verdad?

Yo soy amante de la musica psytrance y hay una pagina muy buena a la que solo cierta seleccion de usuarios pueden entrar, y me encantaria entrar y descarga la musica que ahi tienen.

OJO: Ya he leeido las normas del foro, y no estoy pidiendo que me digan como hacerlo, claro que si desean hacerlo estare mas que agradecido.

Saludos
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines