Total members 11895 |It is currently Sat Dec 21, 2024 4:02 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





ASP.NET insert, update, delete commands examples
===========Class1.vb==============
Code:

Imports Microsoft
.VisualBasic
Imports System
.Data.SqlClient
Imports System
.Data


Public Class Class1

    Dim objcon As New SqlConnection
(ConfigurationManager.ConnectionStrings("student").ConnectionString)
    Dim objadp As SqlDataAdapter
    Dim ds As Data
.DataSet
    Dim cmd As SqlCommand


    Public Function selectdata
(ByVal qry As String) As DataSet

        objcon
.Open()
        objadp = New SqlDataAdapter(qry, objcon)
        ds = New Data.DataSet
        objadp
.Fill(ds)
        objcon.Close()
        Return ds

    End Function


    Public Function qryexe
(ByVal qry As String) As Boolean
        objcon
.Open()
        cmd = New SqlCommand(qry, objcon)
        Dim i As Integer = cmd.ExecuteNonQuery()
        objcon.Close()
        If i = 0 Then
            Return False
        Else
            Return True
        End If

    End Function
End Class
 
====================Default.aspx.vb========================
Code:

Partial Class _Default
    Inherits System
.Web.UI.Page

    Dim qry As String
    Dim ds As New System
.Data.DataSet
    Dim obj As New Class1
    Shared flag As Boolean 
= False
    Shared chk As Boolean

    Protected Sub Button1_Click
(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        chk 
= True
    End Sub

    Protected Sub Button2_Click
(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        chk 
= False
    End Sub

    Protected Sub Button3_Click
(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        qry 
= "delete from stud where name='" + DropDownList1.SelectedItem.Text + "'"
        obj.qryexe(qry)
        flag = False
        Page_Load
(sender, e)
        trno.Text = ""
        tname.Text = ""
        tresult.Text = ""
    End Sub

    Public Sub display
()
        qry = "select * from stud where name='" + DropDownList1.SelectedItem.Text + "'"
        ds = obj.selectdata(qry)
        trno.Text = ds.Tables(0).Rows(0).Item("rno").ToString()
        tname.Text = ds.Tables(0).Rows(0).Item("name")
        tresult.Text = ds.Tables(0).Rows(0).Item("result")
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged
(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        ds
.Clear()
        display()
    End Sub

   

    Protected Sub Page_Load
(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If flag 
= False Then
            ds
.Clear()
            qry = "select * from stud"
            ds = obj.selectdata(qry)
            DropDownList1.DataSource = ds
            DropDownList1
.DataTextField = ds.Tables(0).Columns("name").ToString()
            DropDownList1.DataValueField = ds.Tables(0).Columns("rno").ToString()
            DropDownList1.DataBind()

            GridView1.DataSource = ds
            GridView1
.DataBind()

           

            flag 
= True
        End If
    End Sub

    Protected Sub Button4_Click
(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        If chk 
= True Then
            qry 
= "insert into stud(name,result) values('" + tname.Text.Trim + "','" + tresult.Text.Trim + "')"
            obj.qryexe(qry)
        Else
            qry 
= "update stud set name='" + tname.Text.Trim + "',result='" + tresult.Text.Trim + "' where rno=" + trno.Text.Trim
            obj
.qryexe(qry)
        End If
        flag 
= False
        Page_Load
(sender, e)
        trno.Text = ""
        tname.Text = ""
        tresult.Text = ""
    End Sub

   
End Class
 
======================
:duel:




Attachments:
Class1.vb.txt [1.76 KiB]
Downloaded 948 times
Default.aspx.vb.txt [4.38 KiB]
Downloaded 1108 times
Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Asp.net insert update delete Examples
 DML Statements, insert row, delete row     -  
 examples with c     -  
 Examples in C#     -  
 few examples of c using ascii     -  
 Examples of heading tags     -  
 Matlab basics examples     -  
 vBulletin update     -  
 insert query example     -  
 update query example     -  
 Insert using native query     -  



Topic Tags

ASP MYSQL






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com