2015-02-24 82 views
0
Imports System.Data.OleDb 

Namespace wbdsproject 

    Partial Class frmUserPrvMsg 
     Inherits System.Web.UI.Page 

     Dim topicDb As OleDbConnection 
     Dim topicCmd As OleDbCommand 
     Dim topicReader As OleDbDataReader 
     Dim topicId As Integer 
     Dim AuthorName, Username As String 

    #Region " Web Form Designer Generated Code " 

     'This call is required by the Web Form Designer. 
     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() 

     End Sub 


     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 
      'CODEGEN: This method call is required by the Web Form Designer 
      'Do not modify it using the code editor. 
      InitializeComponent() 
     End Sub 

    #End Region 

     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load 
      'Put user code to initialize the page here 
      Dim uid As Int16 
      topicId = Request.QueryString("topicId") 
      topicDb = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\discussion\SampleForum.mdb") 
      topicDb.Open() 
      If Session("loginuser") = "" Then 
       Response.Redirect("frmlogin.aspx") 
      End If 
      Username = Session("loginuser") 
      topicCmd = New OleDbCommand("select uid from tbllog where uname='" & Username & "'", topicDb) 
      uid = topicCmd.ExecuteScalar 
      topicCmd = New OleDbCommand("Select uname,pMsgDate,pMsgSubject,pMsgDetail from tblprivatemessage, tbllog where tblprivatemessage.pMsgTo=" & uid & " and tbllog.uid=tblprivatemessage.pMsgFrom", topicDb) 
      topicReader = topicCmd.ExecuteReader 
      DataGrid2.DataSource = topicReader 

      DataGrid2.DataBind() 
      topicReader.Close() 
     End Sub 

     Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 

     End Sub 

     Private Sub btninbox_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btninbox.Click 
      Response.Redirect("frmUserPrvMsg.aspx") 
     End Sub 

     Private Sub btnOutBox_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnOutBox.Click 
      Response.Redirect("OutBox.aspx") 
     End Sub 
    End Class 
End Namespace 

初学者,只需我运行无法理解unknoen problem.any soutions从'DBNull'类型到'Short'类型的转换无效。在.NET .NET

回答

1

你的命令

select uid from tbllog where uname='UserName' 

正在返回的DBNull。

本主题应该会有所帮助:DBNull check for Execute Scalar

+0

而一个DBNull的结果意味着存在具有指定名称的用户。 – 2015-02-24 08:31:54

相关问题