Friday, July 23, 2010
multiple data store in table
{
SqlConnection con = new SqlConnection("server=INFO-PROJECT4\\SQLEXPRESS;database=nss;integrated security=true");
con.Open();
SqlCommand cmd = new SqlCommand("insert into sss(city) values(@city)",con);
cmd.Parameters.AddWithValue("@city", listBox1.SelectedItems[i].ToString());
cmd.ExecuteNonQuery();
MessageBox.Show("success");
con.Close();
}
Thursday, July 22, 2010
ASP.NET Grid View Insert,Update,select,Edit
Design:
Step 1:In edit column add 1 boundfield(E.No),5 templatefield(name,address,gender,qualification),1 templatefield(Edit),1 Command Field(delete--in property select show deleteButton).
Step 2: In Edit Template
Name - add label in item template ,textbox in edit template and footer template
similarly(address,gender,qualification,,edit)
aspx.cs page
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class parthigrid : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=iNFO-PROJECT4\\SQLEXPRESS;database=register;integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
view();
}
}
void view()
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from grid1 order by serialno asc", con);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("insert"))
{
TextBox tfname = (TextBox)GridView1.FooterRow.FindControl("txtfname");
TextBox tffaddress = (TextBox)GridView1.FooterRow.FindControl("txtfaddress");
RadioButtonList rbtnffgender = (RadioButtonList)GridView1.FooterRow.FindControl("rbtnlfgender");
DropDownList ddfquali = (DropDownList)GridView1.FooterRow.FindControl("ddlfquali");
con.Open();
SqlCommand cmd = new SqlCommand("insert into grid1(name,address,gender,quali) values(@na,@add,@gen,@qual) ", con);
cmd.Parameters.AddWithValue("@na", tfname.Text);
cmd.Parameters.AddWithValue("@add", tffaddress.Text);
cmd.Parameters.AddWithValue("@gen", rbtnffgender.SelectedValue);
cmd.Parameters.AddWithValue("@qual", ddfquali.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
view();
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
TextBox txname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname");
TextBox txaddress = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtaddress");
RadioButtonList rbtngender = (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("rbtnlgender");
DropDownList ddquali = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlquali");
con.Open();
SqlCommand cmd = new SqlCommand("update grid1 set name=@na,address=@ad,gender=@gen,quali=@qual where serialno=@i", con);
cmd.Parameters.AddWithValue("@i", id);
cmd.Parameters.AddWithValue("@na", txname.Text);
cmd.Parameters.AddWithValue("@ad", txaddress.Text);
cmd.Parameters.AddWithValue("@gen", rbtngender.SelectedValue);
cmd.Parameters.AddWithValue("@qual", ddquali.SelectedValue);
// cmd.Parameters.AddWithValue("@Country", Country);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
view();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
String id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM grid1 where serialno=@i", con);
cmd.Parameters.AddWithValue("@i", id);
cmd.ExecuteNonQuery();
view();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
view();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
view();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
view();
}
}
Wednesday, July 14, 2010
Asp.Net Client side Validation using Java Script
This simple program will guide how to do client side validation of Form in
In this just make a form as follows:
Now on the sourcecode of this form in script tag write the following code:
<script language="javascript" type="text/javascript">
function validate()
{
if (document.getElementById("<%=txtName.ClientID%>").value=="")
{
alert("Name Feild can not be blank");
document.getElementById("<%=txtName.ClientID%>").focus();
return false;
}
if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
{
alert("Email id can not be blank");
document.getElementById("<%=txtEmail.ClientID %>").focus();
return false;
}
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid=document.getElementById("<%=txtEmail.ClientID %>").value;
var matchArray = emailid.match(emailPat);
if (matchArray == null)
{
alert("Your email seems incorrect. Please try again.");
document.getElementById("<%=txtEmail.ClientID %>").focus();
return false;
}
if(document.getElementById("<%=txtWebURL.ClientID %>").value=="")
{
alert("Web URL can not be blank");
document.getElementById("<%=txtWebURL.ClientID %>").value="http://"
document.getElementById("<%=txtWebURL.ClientID %>").focus();
return false;
}
var Url="^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"
var tempURL=document.getElementById("<%=txtWebURL.ClientID%>").value;
var matchURL=tempURL.match(Url);
if(matchURL==null)
{
alert("Web URL does not look valid");
document.getElementById("<%=txtWebURL.ClientID %>").focus();
return false;
}
if (document.getElementById("<%=txtZIP.ClientID%>").value=="")
{
alert("Zip Code is not valid");
document.getElementById("<%=txtZIP.ClientID%>").focus();
return false;
}
var digits="0123456789";
var temp;
for (var i=0;i
{
temp=document.getElementById("<%=txtZIP.ClientID%>").value.substring(i,i+1);
if (digits.indexOf(temp)==-1)
{
alert("Please enter correct zip code");
document.getElementById("<%=txtZIP.ClientID%>").focus();
return false;
}
}
return true;
}
script>
And in code behind file just write the below code.
protected void Page_Load(object sender, EventArgs e)
{
btnSubmit.Attributes.Add("onClick", " return validate()");
}
Tuesday, July 13, 2010
C#.net Extract numbers fron string
1. add textbox ,label and button to form
2.textbox contain string number means it numbers
3.textbox contain only strings means it returns value "zero"
4.min,max amount validation for done here..
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static string ExtractNumbers(string expr)
{
return string.Join(null, System.Text.RegularExpressions.Regex.Split(expr, "[^\\d]"));
}
private void button2_Click(object sender, EventArgs e)
{
string numValue = ExtractNumbers(textBox1.Text);
if (numValue != "")
{
string aString = numValue;
int aInt = int.Parse(aString);
if (aInt >= 100 && aInt <= 40000)
{
label1.Text = Convert.ToString(aInt + ".00");
}
else
{
label1.Text = "Not valid";
}
}
else
{
label1.Text = "0";
}
}
}
}
C#.Net DataGridView Insert,Update,Select,Delete using Stored procedure
C#.Net DataGridView Insert,Update,Select,Delete using Stored procedure
1.create new winform add one datagrid ,3 label and 3 TextBox
2. add 3 button for insert,update,delete
3.create stored procedure for all
Inset query using stored Procedure:
create procedure insertemp1 (@id int,@name varchar(100),@sal int)
As
insert into parthi values(@id,@name,@sal)
Select query using stored Procedure:
Create Procedure insertemp2
As
SELECT * FROM parthi
Update query using stored procedure:
create procedure insertemp3 (@id int,@name varchar(100),@sal int)
As
update parthi set name=@name,salary=@sal where id=(@id)
Delete query using stored procedure:
create procedure insertemp4(@id int) as
delete from parthi where id=@id
Form1.cs:
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 gridEdit
{
public partial class Form1 : Form
{
SqlConnection con =new SqlConnection("server =192.168.3.150;uid=sa;pwd=sa@1234;database=nss1");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//this.Size = Screen.PrimaryScreen.Bounds.Size;
//this.Location = new Point(0, 0);
SqlCommand command = new SqlCommand("insertemp2", con);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "parthi");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "parthi";
}
private void btninsert_Click(object sender, EventArgs e)
{
int txtid =Convert.ToInt32(textBox1.Text);
string txtname = textBox2.Text;
int txtsal = int.Parse(textBox3.Text);
SqlCommand cmd = new SqlCommand("insertemp1", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insertemp1";
cmd.Parameters.AddWithValue("@id", txtid);
cmd.Parameters.AddWithValue("@name", txtname);
cmd.Parameters.AddWithValue("@sal", txtsal);
cmd.ExecuteNonQuery();
MessageBox.Show("inserted......");
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
int txtid = Convert.ToInt32(textBox1.Text);
string txtname = textBox2.Text;
int txtsal = int.Parse(textBox3.Text);
SqlCommand cmd = new SqlCommand("insertemp3", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insertemp3";
cmd.Parameters.AddWithValue("@id", txtid);
cmd.Parameters.AddWithValue("@name", txtname);
cmd.Parameters.AddWithValue("@sal", txtsal);
cmd.ExecuteNonQuery();
MessageBox.Show("updated......");
con.Close();
}
private void button3_Click(object sender, EventArgs e)
{
int txtid = Convert.ToInt32(textBox1.Text);
SqlCommand cmd = new SqlCommand("insertemp4", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insertemp4";
cmd.Parameters.AddWithValue("@id", txtid);
cmd.ExecuteNonQuery();
MessageBox.Show("deleted......");
con.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int i;
i = dataGridView1.SelectedCells[0].RowIndex;
textBox1.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
}
}
}
final output window:
C# .net datagridview add,update,delete
Thursday, July 1, 2010
how to create word Documet in c#.net
step2:add reference in COM component
step3:add reference in .NET component
step4:Design page add one richtextbox and one button
sql innerjoin,max and sub qyery
Wednesday, June 16, 2010
csharp Drawing
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.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
namespace paint1
{
public partial class Form1 : Form
{
Pen Pn;
Point Pt;
Graphics g;
Pen Pn2;
Point Pt2;
Graphics g2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap fImage = new Bitmap(pictureBox1.Image);
MemoryStream ms = new MemoryStream();
fImage.Save(ms, ImageFormat.Jpeg);
fImage.Save("C:\\CaptureVideo\\aa.Jpeg");
// fImage.Save("\\\\192.168.3.96\\CaptureVideo\\aa.Jpeg");
// byte[] bitmapData = ms.ToArray();
if (System.IO.File.Exists("C:\\cc.Jpeg"))
{
System.IO.File.Delete("C:\\cc.Jpeg");
File.Copy("C:\\CaptureVideo\\aa.Jpeg", "C:\\cc.Jpeg");
Image im = Image.FromFile("C:\\cc.Jpeg");
pictureBox2.Image = im;
button1.Enabled = false;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
g.DrawLine(Pn, Pt.X, Pt.Y, e.X, e.Y);
pictureBox1.Refresh();
Pt = e.Location;
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Pt = e.Location;
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Parent = this;
Pn = new Pen(Color.Black, 4);
Pn.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(pictureBox1.Image);
g.Clear(Color.White);
pictureBox2.Parent = this;
Pn2 = new Pen(Color.Black, 4);
Pn2.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
pictureBox2.Image = new Bitmap(pictureBox2.Width, pictureBox2.Height);
g2 = Graphics.FromImage(pictureBox2.Image);
g2.Clear(Color.White);
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Parent = this;
Pn = new Pen(Color.Black, 4);
Pn.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(pictureBox1.Image);
g.Clear(Color.White);
if (System.IO.File.Exists("C:\\cc.Jpeg"))
{
pictureBox2.Image.Dispose();
pictureBox2.Image = null;
pictureBox2.Parent = this;
Pn2 = new Pen(Color.Black, 4);
Pn2.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
pictureBox2.Image = new Bitmap(pictureBox2.Width, pictureBox2.Height);
g2 = Graphics.FromImage(pictureBox2.Image);
g2.Clear(Color.White);
button1.Enabled = true;
}
}
}
}
C#.net play VLC player
axVLCPlugin1.addTarget("C:\\hindi.mp4", null, AXVLC.VLCPlaylistMode.VLCPlayListReplace,0);
axVLCPlugin1.play();
Web Cam Capture:
axVLCPlugin1.addTarget("dshow://",new string[] { ":dshow-vdev=Logitech QuickCam Pro 9000", ":dshow-adev=\"\"", ":dshow-size=\"320x240\"" },AXVLC.VLCPlaylistMode.VLCPlayListAppendAndGo, -666);