Thursday, May 14, 2015

Image Split

public static void ImageSplit(string Filname)
        {
            // string Filname = @"E:\dodge_image\2.tif";
            Image img = Image.FromFile(Filname); // a.png has 312X312 width and height
            //int widthThird = (int)((double)img.Width / 3.0 + 0.5);
            //int heightThird = (int)((double)img.Height / 3.0 + 0.5);

            int widthThird = (int)((double)img.Width / 8.0 + 3.0);
            int heightThird = (int)((double)img.Height / 8.0 + 3.0);

            int k = 0;
            Bitmap[,] bmps = new Bitmap[8, 8];
            for (int i = 0; i < 8; i++)
                for (int j = 0; j < 8; j++)
                {
                    bmps[i, j] = new Bitmap(widthThird, heightThird);
                    Graphics g = Graphics.FromImage(bmps[i, j]);
                    g.DrawImage(img, new Rectangle(0, 0, widthThird, heightThird), new Rectangle(j * widthThird, i * heightThird, widthThird, heightThird), GraphicsUnit.Pixel);
                    g.Dispose();
                    if (!Directory.Exists("E:\\output\\" + Path.GetFileNameWithoutExtension(Filname)))
                        Directory.CreateDirectory("E:\\output\\" + Path.GetFileNameWithoutExtension(Filname));
                    bmps[i, j].Save("E:\\output\\" + Path.GetFileNameWithoutExtension(Filname) + "\\" + Path.GetFileNameWithoutExtension(Filname) + "_" + k + ".bmp", ImageFormat.Bmp);
                    k++;
                }

        }

Wednesday, May 6, 2015

Read from SQL Table and Write as XML File




Read from SQL Table and Write as XML File:

 string Coon = ConfigurationManager.ConnectionStrings["ConnectionSQL"].ConnectionString;

            SqlDataAdapter DA = null;
            DataSet ds = new DataSet();
            DataTable dt = null;
            SqlConnection Con = new SqlConnection(Coon);
            string Query = "SELECT ID,NAME,SALARY,CITY FROM Customer FOR XML                    RAW('Customer'), ROOT('Customers'), ELEMENTS";

            XmlReader reader;
            XmlDocument xmlDoc;
            SqlCommand cmd = null;

            cmd = new SqlCommand(Query, Con);
            Con.Open();
            reader = cmd.ExecuteXmlReader();
            xmlDoc = new XmlDocument();
            while (reader.Read())
            {
                xmlDoc.Load(reader);
            }
            if (File.Exists(@"C:\sample.xml"))
            {
                File.Delete(@"C:\sample.xml");
                xmlDoc.Save(@"C:\sample.xml");
            }
            else
            {
                xmlDoc.Save(@"C:\sample.xml");
            }

            Con.Close();

            MessageBox.Show("Completed");


Read XML File and  Display in List

     XmlReader xReader = XmlReader.Create(@"E:\sample.xml");
            while (xReader.Read())
            {
                switch (xReader.NodeType)
                {
                    case XmlNodeType.Element:
                        listBox1.Items.Add("<" + xReader.Name + ">");
                        break;
                    case XmlNodeType.Text:
                        listBox1.Items.Add(xReader.Value);
                        break;
                    case XmlNodeType.EndElement:
                        listBox1.Items.Add("</" + xReader.Name + ">");
                        break;
                }
            }

Encrypt and Decrypt Web.config File

For Encryption:


Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSection =config.GetSection("connectionStrings");
            if (!configSection.SectionInformation.IsProtected)
            {
                configSection.SectionInformation.
                    ProtectSection("DataProtectionConfigurationProvider");
                config.Save();
                Response.Write("ConnectionStrings has been encryted successfully.");
            }
            else
            {
                Response.Write("ConnectionStrings has been encryted, this action has been cancled");
            }





For Decryption:

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            ConfigurationSection configSect = config.GetSection("connectionStrings");
            if (configSect.SectionInformation.IsProtected)
            {
                configSect.SectionInformation.UnprotectSection();
                config.Save();
                Response.Write("ConnectionStrings has been Decrypted successfully.");

            }

Thursday, May 9, 2013

Sql Injection Reference

http://resources.infosecinstitute.com/dumping-a-database-using-sql-injection/

RUN Command ShortCuts



1. Accessibility Controls - access.cpl
2. Accessibility Wizard - accwiz
3. Add Hardware Wizard - hdwwiz.cpl
4. Add/Remove Programs - appwiz.cpl
5. Administrative Tools - control admintools
6. Automatic Updates - wuaucpl.cpl
7. Bluetooth Transfer Wizard - fsquirt
8. Calculator - calc
9. Certificate Manager - certmgr.msc
10. Character Map - charmap
11. Check Disk Utility - chkdsk
12. Clipboard Viewer - clipbrd
13. Command Prompt - cmd
14. Component Services - dcomcnfg
15. Computer Management - compmgmt.msc
16. Control Panel - control
17. Date and Time Properties - timedate.cpl
18. DDE Shares - ddeshare
19. Device Manager - devmgmt.msc
20. Direct X Troubleshooter - dxdiag
21. Disk Cleanup Utility - cleanmgr
22. Disk Defragment - dfrg.msc
23. Disk Management - diskmgmt.msc
24. Disk Partition Manager - diskpart
25. Display Properties - control desktop
26. Display Properties - desk.cpl
27. Dr. Watson System Troubleshooting­ Utility - drwtsn32
28. Driver Verifier Utility - verifier
29. Event Viewer - eventvwr.msc
30. Files and Settings Transfer Tool - migwiz
31. File Signature Verification Tool - sigverif
32. Findfast - findfast.cpl
33. Firefox - firefox
34. Folders Properties - control folders
35. Fonts - control fonts
36. Fonts Folder - fonts
37. Free Cell Card Game - freecell
38. Game Controllers - joy.cpl
39. Group Policy Editor (for xp professional) - gpedit.msc
40. Hearts Card Game - mshearts
41. Help and Support - helpctr
42. HyperTerminal - hypertrm
43. Iexpress Wizard - iexpress
44. Indexing Service - ciadv.msc
45. Internet Connection Wizard - icwconn1
46. Internet Explorer - iexplore
47. Internet Properties - inetcpl.cpl
48. Keyboard Properties - control keyboard
49. Local Security Settings - secpol.msc
50. Local Users and Groups - lusrmgr.msc
51. Logs You Out Of Windows - logoff
52. Malicious Software Removal Tool - mrt
53. Microsoft Chat - winchat
54. Microsoft Movie Maker - moviemk
55. Microsoft Paint - mspaint
56. Microsoft Syncronization Tool - mobsync
57. Minesweeper Game - winmine
58. Mouse Properties - control mouse
59. Mouse Properties - main.cpl
60. Netmeeting - conf
61. Network Connections - control netconnections
62. Network Connections - ncpa.cpl
63. Network Setup Wizard - netsetup.cpl
64. Notepad - notepad
65. Object Packager - packager
66. ODBC Data Source Administrator - odbccp32.cpl
67. On Screen Keyboard - osk
68. Outlook Express - msimn
69. Paint - pbrush
70. Password Properties - password.cpl
71. Performance Monitor - perfmon.msc
72. Performance Monitor - perfmon
73. Phone and Modem Options - telephon.cpl
74. Phone Dialer - dialer
75. Pinball Game - pinball
76. Power Configuration - powercfg.cpl
77. Printers and Faxes - control printers
78. Printers Folder - printers
79. Regional Settings - intl.cpl
80. Registry Editor - regedit
81. Registry Editor - regedit32
82. Remote Access Phonebook - rasphone
83. Remote Desktop - mstsc
84. Removable Storage - ntmsmgr.msc
85. Removable Storage Operator Requests - ntmsoprq.msc
86. Resultant Set of Policy (for xp professional) - rsop.msc
87. Scanners and Cameras - sticpl.cpl
88. Scheduled Tasks - control schedtasks
89. Security Center - wscui.cpl
90. Services - services.msc
91. Shared Folders - fsmgmt.msc
92. Shuts Down Windows - shutdown
93. Sounds and Audio - mmsys.cpl
94. Spider Solitare Card Game - spider
95. SQL Client Configuration - cliconfg
96. System Configuration Editor - sysedit
97. System Configuration Utility - msconfig
98. System Information - msinfo32
99. System Properties - sysdm.cpl
100. Task Manager - taskmgr
101. TCP Tester - tcptest
102. Telnet Client - telnet
103. User Account Management - nusrmgr.cpl
104. Utility Manager - utilman
105. Windows Address Book - wab
106. Windows Address Book Import Utility - wabmig
107. Windows Explorer - explorer
108. Windows Firewall - firewall.cpl
109. Windows Magnifier - magnify
110. Windows Management Infrastructure - wmimgmt.msc
111. Windows Media Player - wmplayer
112. Windows Messenger - msmsgs
113. Windows System Security Tool - syskey
114. Windows Update Launches - wupdmgr
115. Windows Version - winver
116. Wordpad - write

Monday, November 7, 2011

Auto start/stop timer when keyboard& Mouse idle mode

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.Diagnostics;
using System.Threading;


namespace afp_Login
{
public partial class Form2 : Form
{
int Timecounter = 0;
Stopwatch stopwarch;
TimeSpan ts;

public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
timer1.Start();
timer2.Start();
stopwarch = new Stopwatch();
stopwarch.Start();

}
private void timer1_Tick(object sender, EventArgs e)
{
ts = stopwarch.Elapsed;
string Elapsedtime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
lblTime.Text = Elapsedtime.ToString();

}

private void timer2_Tick(object sender, EventArgs e)
{
Timecounter++;
if (Timecounter > 30 && timer1.Enabled == true)
{
stopwarch.Stop();
timer1.Stop();
}
else if (Timecounter < 30 && timer1.Enabled == false)
{
stopwarch.Start();
timer1.Start();
}

}

private void Form2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
Timecounter = 0;
}

private void Form2_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Timecounter = 0;
}

}
}

Friday, July 29, 2011

Nth Highest salary

declare @empsal int
set @empsal=3
select * from [Employee-new] e1 where @empsal =( select count(distinct e2.empsal) from [Employee-new] e2 where e2.empsal >= e1.empsal)

Thursday, April 28, 2011

HTML WITH MS Access DB

html
head
script language="JavaScript"

function getSubmit()
{
var Firstn = names.value;
var LastName =surname.value;
var cn = new ActiveXObject("ADODB.Connection");
//here you must use forward slash to point strait
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:/clientDB.mdb";
var rs = new ActiveXObject("ADODB.Recordset");
//var SQL = "INSERT INTO Customers(Fname, Lname) VALUES ( '"+ Firstn +"', '" + LastName +"')";
var SQL = "select Surname from Customers where Fname = '" + Firstn + "'";
cn.Open(strConn);
rs.Open(SQL, cn);
surname.value= rs(0);
//DOB.value = rs(1);
//alert(rs(0));
rs.Close();
cn.Close();
}
/script
/head
body
input type="text" name="names"
input type="text" name="surname"
input type="button" value="submit" onclick="getSubmit()"
/body
/html

Monday, April 11, 2011

Query for delete data from first table and copy into second table

Query for delete data from first table and copy into second table

Ans:

DELETE OldTableName
OUTPUT deleted.* INTO NewTableName

Friday, July 23, 2010

multiple data store in table

for (int i=0; i < this.listBox1.SelectedItems.Count; i++)
{


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:

  • Name : <asp:TextBox ID="txtName" />
  • Email : <asp:TextBox ID="txtEmail" />
  • Web URL : <asp:TextBox ID="txtWebUrl" />
  • Zip : <asp:TextBox ID="txtZip" />
  • <asp:Button ID="btnSubmit" OnClientClick=" return validate()" runat="server" Text="Submit" />

  • 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"<%=txtZIP.ClientID %>"
    ).value.length;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

    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

    http://www.dotnetspark.com/kb/608-how-to-get-values-slected-cell-row-datagridviewwindows.aspx

    Thursday, July 1, 2010

    how to create word Documet in c#.net

    step1:create your project name it as MS Word
    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

    select A1.Name,A1.AccountNumber,B1.MessageText,B1.MessageID from Customers a1 inner join SMSRecieved b1 on B1.PhoneNo=A1.MobileNumber where B1.PhoneNo ='" + txtMobileNumber.Text + "' and b1.ReceivedTime =(select max(ReceivedTime) from SMSRecieved where PhoneNo='" + txtMobileNumber.Text + "')

    Wednesday, June 16, 2010

    csharp Drawing

    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.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

    Write Button Click:


    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);