Thursday, May 26, 2011

Asp .net....I have got chance to learn asp .net...Here few codes which i tried and worked...:-)

T o check case sensitive in asp .net
Private Sub checkpwd()
Dim oODBCConnection As OdbcConnection
Dim ConnString As String = "Server=LOCALHOST;" & "Database=premier;" & "provider=.NET Framework Data Provider for ODBC;" & "dsn=premier;" & "Uid=root;" & "Pwd=123456"
oODBCConnection = New Odbc.OdbcConnection(ConnString)

Dim user As String = (DirectCast(FindControl("TextBox1"), TextBox)).Text
Dim pswd As String = (DirectCast(FindControl("TextBox2"), TextBox)).Text

Dim pwdqry As String = "Select Password from log_auth where username=? and password=?"
Dim pwdcmd As New OdbcCommand(pwdqry, oODBCConnection)
pwdcmd.Parameters.AddWithValue("@user", User)
pwdcmd.Parameters.AddWithValue("@pswd", pswd)
MsgBox(User)
MsgBox(pswd)
oODBCConnection.Open()
Dim dr1 As OdbcDataReader = pwdcmd.ExecuteReader
' dr1 = pwdcmd.ExecuteReader
If dr1.Read() Then
'MsgBox(dr1(0))
Dim enterpwd As String = dr1(0)
MsgBox(enterpwd)
End If


Dim res As String
res = String.Compare(pswd, dr1(0), False)
MsgBox(res)
If res = "0" Then
MsgBox("matching password")
Response.Redirect("Default.aspx")
Else
MsgBox("Password is not correct")
End If

End Sub
Note: To check case sensitive using compare string in “res = String.Compare(pswd, dr1(0), False)”

To check login username and Password:

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim user As String = (DirectCast(FindControl("TextBox1"), TextBox)).Text
Dim pswd As String = (DirectCast(FindControl("TextBox2"), TextBox)).Text


Dim oODBCConnection As OdbcConnection
Dim ConnString As String = "Server=LOCALHOST;" & "Database=premier;" & "provider=.NET Framework Data Provider for ODBC;" & "dsn=premier;" & "Uid=root;" & "Pwd=123456"
oODBCConnection = New Odbc.OdbcConnection(ConnString)


Dim myselectQuery As String = "Select * from log_auth where username=? and password=?"
Dim myOdbcCommand As New OdbcCommand(myselectQuery, oODBCConnection)

myOdbcCommand.Parameters.AddWithValue("@user", user)
myOdbcCommand.Parameters.AddWithValue("@pswd", pswd)

oODBCConnection.Open()

Dim dr As OdbcDataReader
dr = myOdbcCommand.ExecuteReader

If dr.HasRows Then


checkpwd()

Else
Label3.Text = "User not authenticated to login this page"
'MsgBox("User not authenticated to login this page")

End If



'myOdbcCommand.ExecuteNonQuery()
'oODBCConnection.Close()


End Sub

To go from one aspx to another aspx page:

Response.Redirect("Default.aspx");


To Hide and unhide columns in gridview1

Gridview1.Columns(x).Visible = False


Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

Label1.Visible = False
DropDownList1.Visible = False
Button1.Visible = False
GridView1.Visible = True
GridView1.Columns(0).Visible = True
GridView1.Columns(1).Visible = True
GridView1.Columns(2).Visible = True
GridView1.Columns(3).Visible = False
GridView1.Columns(4).Visible = True
'GridView1.Columns(5).Visible = True

'MsgBox("database checked")


End Sub


TO get results In button_click, rediobutton.checkchanges

Change properties as AutoPostback = False

Note: to execute code in events and actions for buttons or pages.
Autopostback: Automatically Postback to the server when the control is clicked.

To create dropdownlist and populate values for that dropdown in page




'Dim myselectQuery As String = "SELECT dsn_id, dsn_name FROM premier.rm_dsn_source"
Dim myOdbcCommand As New OdbcCommand("SELECT dsn_id, dsn_name FROM premier.rm_dsn_source", oODBCConnection)
If oODBCConnection.State = ConnectionState.Closed Then
oODBCConnection.Open()
End If


Dim myDA As OdbcDataAdapter
Dim myDataSet As DataSet

myDA = New OdbcDataAdapter(myOdbcCommand)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
If myDataSet.Tables(0).Rows.Count > 0 Then

'GridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
'GridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
'GridView1.DataSource = SqlDataSource1
DropDownList1.DataSource = myDataSet.Tables(0)
DropDownList1.DataTextField = "dsn_name"
DropDownList1.DataValueField = "dsn_id"

MsgBox(GridView1.Columns.Count)
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "--Select--")

Else

MsgBox("no database available")
End If
Code for dropdownlist field:

'----odbc connection - start
Dim oODBCConnection As OdbcConnection
Dim ConnString As String = "Server=LOCALHOST;" & "Database=premier;" & "provider=.NET Framework Data Provider for ODBC;" & "dsn=premier;" & "Uid=root;" & "Pwd=123456"
oODBCConnection = New System.Data.Odbc.OdbcConnection(ConnString)
oODBCConnection.Open()
'----odbc connection - end


'----------code to get details for dropdownlist values- start
'Dim myselectQuery As String = "SELECT dsn_id, dsn_name FROM premier.rm_dsn_source"
Dim myOdbcCommand As New OdbcCommand("SELECT dsn_id, dsn_name FROM premier.rm_dsn_source", oODBCConnection)
Dim myDA As OdbcDataAdapter
Dim myDataSet As DataSet

myDA = New OdbcDataAdapter(myOdbcCommand)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
If myDataSet.Tables(0).Rows.Count > 0 Then

'GridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
'GridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
'GridView1.DataSource = SqlDataSource1
DropDownList1.DataSource = myDataSet.Tables(0)
DropDownList1.DataTextField = "dsn_name"
DropDownList1.DataValueField = "dsn_id"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "--Select--")

Else

MsgBox("no database available")
End If
'----------code to get details for dropdownlist - end

No comments: