输入的字符串格式不正确 [英] Input string in the incorect format
问题描述
亲爱的
我曾尝试进行会话.当用户单击登录按钮时,我有一个登录页面.我已经在会话中保存了用户名和密码.
I was tried to working with session. I have a login page, when user click the login button. i have save the User name and Password in the session.
下面是登录事件中的代码段:
below are the code snippet on yhe login event :
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Try
Dim RetrieveCmdQuery As String = "SELECT user.[id], user.[username], user.[password], user.[name] FROM [user] where user.[id] = 1;"
Dim RetrieveCmd As OleDbCommand = New OleDbCommand(RetrieveCmdQuery, DbConn)
Dim Dataset As New DataSet()
Dim dataAdapter As New OleDbDataAdapter(RetrieveCmd)
DbConn.Open()
dataAdapter.FillSchema(Dataset, SchemaType.Source, "USER")
dataAdapter.Fill(Dataset, "USER") 'get error here
If TextBox1.Text <> Dataset.Tables(0).Rows(0).Item("username") Or TextBox2.Text <> Dataset.Tables(0).Rows(0).Item("password") Then
lblError.Text = "Invalid user name or password"
Else
Session.Item("UserName") = TextBox1.Text
Session.Item("Password") = TextBox2.Text
Session.Timeout = 1
Response.Redirect("Home.aspx")
End If
Catch ex As OleDb.OleDbException
Label1.Text = ex.ToString()
Finally
DbConn.Close()
End Try
End Sub
及以下是登录事件后加载首页上的代码片段:
and below are the code snipet on the home page load after login event :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If Session.Item("UserName") Or Session.Item("Password") Is Nothing Then
Response.Redirect("Login.aspx")
End If
End If
If Session("UserName") Or Session("Password") Is Nothing Then
Response.Redirect("Login.aspx")
Else
Dim RetrieveCmdQuery As String = "SELECT user.[id], user.[username], user.[password], user.[name] FROM [user] where user.[id] = 1;"
Dim RetrieveCmd As OleDbCommand = New OleDbCommand(RetrieveCmdQuery, DbConn)
Dim Dataset As New DataSet()
Dim dataAdapter As New OleDbDataAdapter(RetrieveCmd)
DbConn.Open()
dataAdapter.FillSchema(Dataset, SchemaType.Source, "USER")
dataAdapter.Fill(Dataset, "USER")
Label1.Text = Dataset.Tables(0).Rows(0).Item("name").ToString()
End If
End Sub
我的代码有误:如果Session.Item("UserName")或Session.Item("Password")没问题然后
nbsp; bsp Response.Redirect("Login.aspx")
万一
I have error on the code : If Session.Item("UserName") Or Session.Item("Password") Is Nothing Then
Response.Redirect("Login.aspx")
End If
错误消息为:输入字符串为incoreect格式".请告诉我问题是什么,以便我可以解决.谢谢.
The error message are : "Input string was in incoreect format". Please tell me what is the problem, so i can solve it. Thank You.
推荐答案
我不认为这是有效的语法.尝试使用 改为使用String.IsNullOrEmpty 方法.
I don't believe that is valid syntax. Try using the String.IsNullOrEmpty method instead.
这篇关于输入的字符串格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!