Hello friends,
I need an urgent help.I'm doing a project in asp.net which uses vb.net as back end language.I'm using sql 2005.My problem is that I can't retrieve the data from database,but I can insert the data into the table.
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
Public login As New Class1
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim u As String
login.cmd.Connection = login.con
login.cmd.CommandText = "select * from REG where user = '" + RTrim(TextBox1.Text) + "'"
login.cmd.ExecuteNonQuery()
login.rdr = login.cmd.ExecuteReader()
If login.rdr.HasRows = True Then
login.rdr.Read()
u = login.rdr.Item("pwd")
If RTrim(TextBox2.Text) = Trim(u) Then
Response.Redirect("student1.aspx")
End If
Else
MsgBox("Enter correct password", MsgBoxStyle.Critical)
End If
'Try
'Catch ex As Exception
' MsgBox(ex.Message)
'End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
login.connection()
End Sub
End Class
I'm using a class to open the database
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Public Class Class1
Public con As SqlConnection
Public cmd As New SqlCommand
Public rdr As SqlDataReader
Public Function connection()
con = New SqlConnection("Data Source=ANGEL\SQLEXPRESS;Initial Catalog=swas;Integrated Security=True")
con.Open()
Return 0
End Function
End Class
Please help me it's really urgent.:(
Thanks in advance.