Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 9:13 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Asp.net inset update delete
PostPosted: Sun Jul 18, 2010 5:01 am 
Offline
Newbie
User avatar

Joined: Sun Jul 18, 2010 4:44 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

:read:
===========Class1.vb==============
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========================

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 103 times
Default.aspx.vb.txt [4.38 KiB]
Downloaded 98 times
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 delete duplicate rows in mysql using php  PHP Tutorials  msi_333  2
 update query example  PHP examples  msi_333  0
 How to delete/remove images from excel 2007 using POI.  Java  vikash786  0
 Update phpbb to latest version with mods  PHPbb3 support  msi_333  2
 Cannot Delete Computer group  General Discussion  Alfonzo  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team