Saturday, October 18, 2014

insert update delete in gridview in c#

Posted by Gnani Palepu  |  No comments


 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  

 <div dir="ltr" style="text-align: left;" trbidi="on">  
 <span style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: 14px; white-space: pre-wrap;">how to update, search, delete, clear, insert  
 ---------------------------------------------  
 Imports System  
 Imports System.Data  
 Imports System.Data.SqlClient  
 Partial Class viewer  
   Inherits System.Web.UI.Page  
   Dim con As New SqlConnection()  
   Dim cmd As New SqlCommand()  
   Dim dt As New DataTable()  
   Dim da As New SqlDataAdapter  
   Dim connectionstring As String = "server=systemname;database=practice;User ID =sa; password=123;integrated security=false"  
 #Region "btninsert"  
   Protected Sub btninsert_Click(sender As Object, e As System.EventArgs) Handles btninsert.Click  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "employee_details" ' insert  
     cmd.CommandType = CommandType.StoredProcedure  
     Try  
       cmd.Parameters.AddWithValue("@empname", txtempname.Text)  
       cmd.Parameters.AddWithValue("@empno", txtempno.Text)  
       cmd.Parameters.AddWithValue("@empphoneno", txtempphno.Text)  
       cmd.Parameters.AddWithValue("@empdesignation", txtdesignation.Text)  
       cmd.Connection = con  
       cmd.ExecuteNonQuery()  
       con.Close()  
       clearcontrols()  
       ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Record Inserted sucessfully...');", True)  
     Catch ex As Exception  
     End Try  
   End Sub  
 #End Region  
 #Region "btnupdate"  
   Protected Sub btnupdate_Click(sender As Object, e As System.EventArgs) Handles btnupdate.Click  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "employee_update"  
     cmd.CommandType = CommandType.StoredProcedure  
     cmd.Parameters.AddWithValue("@empname", txtempname.Text)  
     cmd.Parameters.AddWithValue("@empno", txtempno.Text)  
     cmd.Parameters.AddWithValue("@empphoneno", txtempphno.Text)  
     cmd.Parameters.AddWithValue("@empdesignation", txtdesignation.Text)  
     cmd.Connection = con  
     cmd.ExecuteNonQuery()  
     con.Close()  
     clearcontrols()  
     ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Record Updated sucessfully...');", True)  
   End Sub  
 #End Region  
 #Region "btnsearch"  
   Protected Sub btnsearch_Click(sender As Object, e As System.EventArgs) Handles btnsearch.Click  
     If txtempno.Text &lt;&gt; "" Then  
       Dim empty As Boolean = search(txtempno.Text)  
       If empty = False Then  
         ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Invalid employee-Code');", True)  
         clearcontrols()  
       End If  
     Else  
       ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Please enter employee-Code');", True)  
     End If  
     txtempno.Focus()  
   End Sub  
 #End Region  
 #Region "search"  
   Public Function search(ByVal asstcodes As String) As Boolean  
     con = New SqlConnection(connectionstring)  
     cmd.CommandText = "Select empname,empno,empphoneno,empdesignation from employee where empno =@empno"  
     cmd.Parameters.AddWithValue("@empno", txtempno.Text)  
     cmd.CommandType = CommandType.Text  
     cmd.Connection = con  
     con.Open()  
     Dim dr As SqlDataReader = cmd.ExecuteReader()  
     While dr.Read  
       txtempname.Text = dr("empname").ToString()  
       txtempno.Text = dr("empno").ToString()  
       txtempphno.Text = dr("empphoneno").ToString()  
       txtdesignation.Text = dr("empdesignation").ToString()  
       con.Close()  
       Return True  
     End While  
     con.Close()  
     Return False  
   End Function  
 #End Region  
 #Region "clear controls"  
   Public Sub clearcontrols()  
     txtempname.Text = Nothing  
     txtempno.Text = Nothing  
     txtempphno.Text = Nothing  
     txtdesignation.Text = Nothing  
   End Sub  
 #End Region  
   Protected Sub btnclear_Click(sender As Object, e As System.EventArgs) Handles btnclear.Click  
     clearcontrols()  
   End Sub  
   Protected Sub btndelete_Click(sender As Object, e As System.EventArgs) Handles btndelete.Click  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "employee_delete"  
     cmd.CommandType = CommandType.StoredProcedure  
     cmd.Parameters.AddWithValue("@empno", txtempno.Text)  
     cmd.Connection = con  
     cmd.ExecuteNonQuery()  
     cmd.Connection = con  
     con.Close()  
     clearcontrols()  
     ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Record Deleted sucessfully');", True)  
   End Sub  
 End Class  
 &lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="register.aspx.vb" Inherits="viewer" %&gt;  
 &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;  
 &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;  
 &lt;head runat="server"&gt;  
   &lt;title&gt;Registration Page&lt;/title&gt;  
 &lt;/head&gt;  
 &lt;body&gt;  
   &lt;form id="form1" runat="server"&gt;  
   &lt;div&gt;  
     &lt;center&gt;  
       &lt;fieldset style="border-style: solid; border-width: 1px; width: 50%;"&gt;  
         &lt;legend&gt;&lt;b&gt;Registration&lt;/b&gt;&lt;/legend&gt;  
         &lt;table width="80%"&gt;  
         &lt;tr&gt;  
             &lt;td style="padding-left: 120px;"&gt;  
               &lt;asp:Label ID="lblempno" runat="server" Text="EMPLOYEENO: "&gt;&lt;/asp:Label&gt;  
             &lt;/td&gt;  
             &lt;td&gt;  
               &lt;asp:TextBox ID="txtempno" runat="server" Width="200px" Style="text-align: left"&gt;&lt;/asp:TextBox&gt;  
             &lt;/td&gt;  
           &lt;/tr&gt;  
           &lt;tr&gt;  
             &lt;td style="padding-left: 120px;"&gt;  
               &lt;asp:Label ID="lblempname" runat="server" Text="EMPLOYEENAME: "&gt;&lt;/asp:Label&gt;  
             &lt;/td&gt;  
             &lt;td&gt;  
               &lt;asp:TextBox ID="txtempname" runat="server" Width="200px" Style="text-align: left"&gt;&lt;/asp:TextBox&gt;  
             &lt;/td&gt;  
           &lt;/tr&gt;  
           &lt;tr&gt;  
             &lt;td style="padding-left: 120px;"&gt;  
               &lt;asp:Label ID="lblempphoneno" runat="server" Text="EMPLOYEEPHONENO: "&gt;&lt;/asp:Label&gt;  
             &lt;/td&gt;  
             &lt;td&gt;  
               &lt;asp:TextBox ID="txtempphno" runat="server" Width="200px" Style="text-align: left"&gt;&lt;/asp:TextBox&gt;  
             &lt;/td&gt;  
           &lt;/tr&gt;  
           &lt;tr&gt;  
             &lt;td style="padding-left: 120px;"&gt;  
               &lt;asp:Label ID="lbldesignation" runat="server" Text="EMPLOYEEDESIGNATION: "&gt;&lt;/asp:Label&gt;  
             &lt;/td&gt;  
             &lt;td&gt;  
               &lt;asp:TextBox ID="txtdesignation" runat="server" Width="200px" Style="text-align: left"&gt;&lt;/asp:TextBox&gt;  
             &lt;/td&gt;  
           &lt;/tr&gt;  
           &lt;tr&gt;  
             &lt;td colspan="2"&gt;  
               &lt;asp:Button ID="btninsert" runat="server" Text="Insert" Height="25px" Width="75px" /&gt;  
               &lt;asp:Button ID="btnsearch" runat="server" Text="search" Height="25px" Width="75px" /&gt;  
               &lt;asp:Button ID="btnupdate" runat="server" Text="Update" Height="25px" Width="75px" /&gt;  
               &lt;asp:Button ID="btndelete" runat="server" Text="Delete" Height="25px" Width="75px" /&gt;  
               &lt;asp:Button ID="btnclear" runat="server" Text="Clear" Height="25px" Width="75px" /&gt;  
             &lt;/td&gt;  
           &lt;/tr&gt;  
         &lt;/table&gt;  
       &lt;/fieldset&gt;  
     &lt;/center&gt;  
   &lt;/div&gt;  
   &lt;/form&gt;  
 &lt;/body&gt;  
 &lt;/html&gt;</span></div>  

 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  


11:48 PM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top