Webocreation

Friday, September 10, 2010

Complete Program To insert, update, show and delete in .Net using ADO

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 databaseinsertion
{
public partial class Form1 : Form
{
int myid;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
SqlCommand scmd = new SqlCommand("productinsertion", sqlcon);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@names", textBox1.Text);
scmd.Parameters.AddWithValue("@description", richTextBox1.Text);
try
{
sqlcon.Open();
scmd.ExecuteNonQuery();
MessageBox.Show("Data Inserted");
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();

}

private void button3_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
string query = "select * from product";
SqlCommand cmd = new SqlCommand(query, sqlcon);
try
{
sqlcon.Open();
SqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
ListViewItem lvt = new ListViewItem();
lvt.Tag=r["id"];
lvt.Text = r["product_name"].ToString();
lvt.SubItems.Add(r["product_desc"].ToString());
listView1.Items.Add(lvt);
}
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();
}

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{

if (listView1.SelectedItems.Count > 0)
{
ListViewItem lv = listView1.SelectedItems[0];
myid=Convert.ToInt32(lv.Tag);
textBox1.Text = lv.Text;
richTextBox1.Text = lv.SubItems[1].Text;
}
}

private void button2_Click(object sender, EventArgs e)
{
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
string product_name = textBox1.Text;
string product_description = richTextBox1.Text;
string query = "updateproduct";
SqlCommand scmd = new SqlCommand(query, sqlcon);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@id",myid);
// MessageBox.Show(myid.ToString());
scmd.Parameters.AddWithValue("@names", product_name);
scmd.Parameters.AddWithValue("@description", richTextBox1.Text);

try
{
sqlcon.Open();
scmd.ExecuteNonQuery();
MessageBox.Show("Data Updated");
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();
}

private void button5_Click(object sender, EventArgs e)
{
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
SqlCommand scmd = new SqlCommand("selectproduct",sqlcon);
scmd.CommandType = CommandType.StoredProcedure;

try
{
sqlcon.Open();
SqlDataReader r = scmd.ExecuteReader();
while (r.Read())
{
ListViewItem lvt = new ListViewItem();
lvt.Tag = r["id"];
lvt.Text = r["product_name"].ToString();
lvt.SubItems.Add(r["product_desc"].ToString());
listView1.Items.Add(lvt);
}
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();


}

private void button4_Click(object sender, EventArgs e)
{
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
string query = "deleteproduct";
SqlCommand scmd = new SqlCommand(query, sqlcon);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@id", myid);
try
{
sqlcon.Open();
scmd.ExecuteNonQuery();
MessageBox.Show("Data Deleted");
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();
}
}
}

delete with the use of stored procedure code in .net and sql

private void button4_Click(object sender, EventArgs e)
{
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
string query = "deleteproduct";
SqlCommand scmd = new SqlCommand(query, sqlcon);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@id", myid);
try
{
sqlcon.Open();
scmd.ExecuteNonQuery();
MessageBox.Show("Data Deleted");
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();
}

Update code in .net using stored procedure

private void button2_Click(object sender, EventArgs e)
{
string constr = "Data Source=NOBEL-PC\\SQLEXPRESS;Initial Catalog=db_ecommerce;user id=rupak;password=rupak";
SqlConnection sqlcon = new SqlConnection(constr);
string product_name = textBox1.Text;
string product_description = richTextBox1.Text;
string query = "updateproduct";
SqlCommand scmd = new SqlCommand(query, sqlcon);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@id",myid);
// MessageBox.Show(myid.ToString());
scmd.Parameters.AddWithValue("@names", product_name);
scmd.Parameters.AddWithValue("@description", richTextBox1.Text);

try
{
sqlcon.Open();
scmd.ExecuteNonQuery();
MessageBox.Show("Data Updated");
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();
}

Click in the listView and type the code to see data from the richTextBox and textbox

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{

if (listView1.SelectedItems.Count > 0)
{
ListViewItem lv = listView1.SelectedItems[0];
myid=Convert.ToInt32(lv.Tag);
textBox1.Text = lv.Text;
richTextBox1.Text = lv.SubItems[1].Text;
}
}

button code to insert data into database with the use of store procedure

button code to insert data into database with the use of store procedure .net code

private void button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=thismaydiffer\\SQLEXPRESS;Initial Catalog=db_name;user id=usernamerupak;password=userpasswordrupak";
SqlConnection sqlcon = new SqlConnection(constr);
SqlCommand scmd = new SqlCommand("productinsertion", sqlcon);
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.AddWithValue("@names", textBox1.Text);
scmd.Parameters.AddWithValue("@description", richTextBox1.Text);
try
{
sqlcon.Open();
scmd.ExecuteNonQuery();
MessageBox.Show("Data Inserted");
}
catch (SqlException se)
{
MessageBox.Show(se.Message);
}
sqlcon.Close();

}

Wednesday, September 1, 2010

Way to unblock the facebook

http://m.facebook.com/
the url will direct the facebook and open it so try it and use it to unblock the facebook and use it properly and be more friendly with your friend