hi
i am facing problem . i had developed one application for upload multiple files(3). that was worked fine. now i had introduce session variable . with the help of that i had used the file name in next page. i had one more page in there it shows only the attached file name. i had written the following codes in the page_load event. so that once the file has attached.it shows the file name.After adding the codes, the errror -" Object reference not set to an instance of an object." is occuring. can anyone tell me wat is the problem
If Session("lmp1") = "Nil"Or Session("lmp1") = ""ThenFile1.Visible =
TrueElseFile1.Visible =
FalseLabel1.Text = Session("lmp1")
EndIf'----------------------If Session("lmp2") = "Nil"Or Session("lmp2") = ""ThenFile2.Visible =
TrueElseFile2.Visible =
FalseLabel2.Text = Session("lmp2")
EndIf'---------------If Session("lmp3") = "Nil"Or Session("lmp3") = ""ThenFile3.Visible =
TrueElseFile3.Visible =
FalseLabel3.Text = Session("lmp3")
EndIf
regards
m.aruanachalam
Did you debug the code, if u did tell me on which line u get the error? or send me the soure code for the page to let me test it (my email: madvisualbasic@.hotmail.com)On which like you are getting the error?
Also did File1/File2/File3 are declared?
That error comes when if some thing is not declared/initialized and it's been used!
PrivateSub Page_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load
'Put user code to initialize the page here
''---------------------
If Session("lmp1") = "Nil"Or Session("lmp1") = ""Then
File1.Visible =True
Else
File1.Visible =False
Label1.Text = Session("lmp1")
EndIf
'----------------------
If Session("lmp2") = "Nil"Or Session("lmp2") = ""Then
File2.Visible =True
Else
File2.Visible =False
Label2.Text = Session("lmp2")
EndIf
'---------------
If Session("lmp3") = "Nil"Or Session("lmp3") = ""Then
File3.Visible =True
Else
File3.Visible =False
Label3.Text = Session("lmp3")
EndIf
'-----------------
If Session("lmp4") = "Nil"Or Session("lmp4") = ""Then
File4.Visible =True
Else
File4.Visible =False
Label4.Text = Session("lmp4")
EndIf
'------------------------
If Session("lmp5") = "Nil"Or Session("lmp5") = ""Then
File5.Visible =True
Else
File5.Visible =False
Label5.Text = Session("lmp5")
EndIf
'------------------
If Session("lmp6") = "Nil"Or Session("lmp6") = ""Then
File6.Visible =True
Else
File6.Visible =False
Label6.Text = Session("lmp6")
EndIf
EndSub
PrivateSub Button1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Button1.Click
Dim udsAsString = "select uid from temp"
Dim msdAsString
Dim dredAs OleDbDataReader
OleDbConnection1.Open()
Dim ccomdAs OleDbCommand =New OleDbCommand(uds, OleDbConnection1)
dred = ccomd.ExecuteReader(CommandBehavior.CloseConnection)
While dred.Read()
msd = dred(0)
EndWhile
dred.Close()
OleDbConnection1.Close()
'-----------------------
If msd = ""Then
Dim udAsString
ud = Session("mem")
Dim imgstream1As Stream
Dim imgstream2As Stream
Dim imgstream3As Stream
Dim imgstream4As Stream
Dim imgstream5As Stream
Dim imgstream6As Stream
Dim imgsize1As Int64
Dim imgsize2As Int64
Dim imgsize3As Int64
Dim imgsize4As Int64
Dim imgsize5As Int64
Dim imgsize6As Int64
Dim imgname1AsString
Dim imgname2AsString
Dim imgname3AsString
Dim imgname4AsString
Dim imgname5AsString
Dim imgname6AsString
Dim stat1AsInteger
Dim stat2AsInteger
Dim stat3AsInteger
Dim stat4AsInteger
Dim stat5AsInteger
Dim stat6AsInteger
Dim mcomAs OleDbConnection
mcom =New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=d:\database\reports.mdb")
Dim cmmdAs OleDbCommand =New OleDbCommand()
mcom.Open()
imgstream1 = File1.PostedFile.InputStream
imgsize1 = File1.PostedFile.ContentLength
imgname1 = File1.PostedFile.FileName
Dim imgcontent1(imgsize1)AsByte
stat1 = imgstream1.Read(imgcontent1, 0, imgsize1)
Dim inp1AsNew OleDbParameter("@.input1", OleDbType.LongVarBinary)
inp1.Value = imgcontent1
cmmd.Parameters.Add(inp1)
imgstream2 = File2.PostedFile.InputStreamimgsize2 = File2.PostedFile.ContentLength
imgname2 = File2.PostedFile.FileName
Dim imgcontent2(imgsize2)AsByte
stat2 = imgstream2.Read(imgcontent2, 0, imgsize2)
Dim inp2AsNew OleDbParameter("@.input2", OleDbType.LongVarBinary)
inp2.Value = imgcontent2
cmmd.Parameters.Add(inp2)
imgstream3 = File3.PostedFile.InputStreamimgsize3 = File3.PostedFile.ContentLength
imgname3 = File3.PostedFile.FileName
Dim imgcontent3(imgsize3)AsByte
stat3 = imgstream3.Read(imgcontent3, 0, imgsize3)
Dim inp3AsNew OleDbParameter("@.input3", OleDbType.LongVarBinary)
inp3.Value = imgcontent3
cmmd.Parameters.Add(inp3)
imgstream4 = File4.PostedFile.InputStreamimgsize4 = File4.PostedFile.ContentLength
imgname4 = File4.PostedFile.FileName
Dim imgcontent4(imgsize4)AsByte
stat4 = imgstream4.Read(imgcontent4, 0, imgsize4)
Dim inp4AsNew OleDbParameter("@.input4", OleDbType.LongVarBinary)
inp4.Value = imgcontent4
cmmd.Parameters.Add(inp4)
imgstream5 = File5.PostedFile.InputStreamimgsize5 = File5.PostedFile.ContentLength
imgname5 = File5.PostedFile.FileName
Dim imgcontent5(imgsize5)AsByte
stat5 = imgstream5.Read(imgcontent5, 0, imgsize5)
Dim inp5AsNew OleDbParameter("@.input5", OleDbType.LongVarBinary)
inp5.Value = imgcontent5
cmmd.Parameters.Add(inp5)
imgstream6 = File6.PostedFile.InputStreamimgsize6 = File6.PostedFile.ContentLength
imgname6 = File6.PostedFile.FileName
Dim imgcontent6(imgsize6)AsByte
stat6 = imgstream6.Read(imgcontent6, 0, imgsize6)
Dim inp6AsNew OleDbParameter("@.input6", OleDbType.LongVarBinary)
inp6.Value = imgcontent6
cmmd.Parameters.Add(inp6)
'---------------------
If imgname1 = ""Then
imgname1 = "Nil"
Else
imgname1 = File1.PostedFile.FileName
EndIf
If imgname2 = ""Then
imgname2 = "Nil"
Else
imgname2 = File2.PostedFile.FileName
EndIf
If imgname3 = ""Then
imgname3 = "Nil"
Else
imgname3 = File3.PostedFile.FileName
EndIf
If imgname4 = ""Then
imgname4 = "Nil"
Else
imgname4 = File4.PostedFile.FileName
EndIf
If imgname5 = ""Then
imgname5 = "Nil"
Else
imgname5 = File5.PostedFile.FileName
EndIf
If imgname6 = ""Then
imgname6 = "Nil"
Else
imgname6 = File6.PostedFile.FileName
EndIf
'----------------------
cmmd.CommandText = "insert into temp([uid],[input1],[name1],[input2],[name2],[input3],[name3],[input4],[name4],[input5],[name5],[input6],[name6])values('" & ud & "',@.input1,'" & imgname1 & "',@.input2,'" & imgname2 & "',@.input3,'" & imgname3 & "',@.input4,'" & imgname4 & "',@.input5, '" & imgname5 & "',@.input6, '" & imgname6 & "')"
cmmd.Connection = mcom
cmmd.ExecuteNonQuery()
mcom.Close()
Else
updates()
EndIf
EndSub
Sub updates()
'-----------------------------
Dim l1AsString
Dim k1AsString = "select name1 from temp"
Dim comAs OleDbCommand =New OleDbCommand(k1, OleDbConnection1)
OleDbConnection1.Open()
Dim rdAs OleDbDataReader
rd = com.ExecuteReader(CommandBehavior.CloseConnection)
While rd.Read()
l1 = rd(0)
EndWhile
Session("inp") = l1
rd.Close()
OleDbConnection1.Close()
'--------------------
Dim l2AsString
Dim k2AsString = "select name2 from temp "
Dim com1As OleDbCommand =New OleDbCommand(k2, OleDbConnection1)
OleDbConnection1.Open()
rd = com1.ExecuteReader(CommandBehavior.CloseConnection)
While rd.Read()
l2 = rd(0)
EndWhile
Session("inp2") = l2
rd.Close()
OleDbConnection1.Close()
'--------------------------
Dim l3AsString
Dim k3AsString = "select name3 from temp "
Dim com3As OleDbCommand =New OleDbCommand(k3, OleDbConnection1)
OleDbConnection1.Open()
rd = com3.ExecuteReader(CommandBehavior.CloseConnection)
While rd.Read()
l3 = rd(0)
EndWhile
Session("inp2") = l3
rd.Close()
OleDbConnection1.Close()
'------------------------------
Dim lw4AsString
Dim kw4AsString = "select name4 from temp "
Dim com4As OleDbCommand =New OleDbCommand(kw4, OleDbConnection1)
OleDbConnection1.Open()
rd = com4.ExecuteReader(CommandBehavior.CloseConnection)
While rd.Read()
lw4 = rd(0)
EndWhile
Session("cyy") = lw4
rd.Close()
OleDbConnection1.Close()
Response.Write(lw4)
'------------------------
Dim lw5AsString
Dim kw5AsString = "select name5 from temp "
Dim com5As OleDbCommand =New OleDbCommand(kw5, OleDbConnection1)
OleDbConnection1.Open()
rd = com5.ExecuteReader(CommandBehavior.CloseConnection)
While rd.Read()
lw5 = rd(0)
EndWhile
Session("inp2") = lw5
rd.Close()
OleDbConnection1.Close()
'--------------------------
Dim lw6AsString
Dim kw6AsString = "select name6 from temp "
Dim com6As OleDbCommand =New OleDbCommand(kw6, OleDbConnection1)
OleDbConnection1.Open()
rd = com6.ExecuteReader(CommandBehavior.CloseConnection)
While rd.Read()
lw6 = rd(0)
EndWhile
Session("inp6") = lw6
rd.Close()
OleDbConnection1.Close()
'----------------------------
Dim udAsString
ud = Session("mem")
Dim uimgstream1As Stream
Dim uimgstream2As Stream
Dim uimgstream3As Stream
Dim uimgstream4As Stream
Dim uimgstream5As Stream
Dim uimgstream6As Stream
Dim uimgsize1As Int64
Dim uimgsize2As Int64
Dim uimgsize3As Int64
Dim uimgsize4As Int64
Dim uimgsize5As Int64
Dim uimgsize6As Int64
Dim uimgname1AsString
Dim uimgname2AsString
Dim uimgname3AsString
Dim uimgname4AsString
Dim uimgname5AsString
Dim uimgname6AsString
uimgstream1 = File1.PostedFile.InputStream
uimgstream2 = File2.PostedFile.InputStream
uimgstream3 = File3.PostedFile.InputStream
uimgstream4 = File4.PostedFile.InputStream
uimgstream5 = File5.PostedFile.InputStream
uimgstream6 = File6.PostedFile.InputStream
uimgsize1 = File1.PostedFile.ContentLength
uimgsize2 = File2.PostedFile.ContentLength
uimgsize3 = File3.PostedFile.ContentLength
uimgsize4 = File4.PostedFile.ContentLength
uimgsize5 = File5.PostedFile.ContentLength
uimgsize6 = File6.PostedFile.ContentLength
uimgname1 = File1.PostedFile.FileName
uimgname2 = File2.PostedFile.FileName
uimgname3 = File3.PostedFile.FileName
uimgname4 = File4.PostedFile.FileName
uimgname5 = File5.PostedFile.FileName
uimgname6 = File6.PostedFile.FileName
Dim uimgcontent1(uimgsize1)AsByte
Dim uimgcontent2(uimgsize2)AsByte
Dim uimgcontent3(uimgsize3)AsByte
Dim uimgcontent4(uimgsize4)AsByte
Dim uimgcontent5(uimgsize5)AsByte
Dim uimgcontent6(uimgsize6)AsByte
Dim ustat1AsInteger
Dim ustat2AsInteger
Dim ustat3AsInteger
Dim ustat4AsInteger
Dim ustat5AsInteger
Dim ustat6AsInteger
ustat1 = uimgstream1.Read(uimgcontent1, 0, uimgsize1)
ustat2 = uimgstream2.Read(uimgcontent2, 0, uimgsize2)
ustat3 = uimgstream3.Read(uimgcontent3, 0, uimgsize3)
ustat4 = uimgstream4.Read(uimgcontent4, 0, uimgsize4)
ustat5 = uimgstream5.Read(uimgcontent5, 0, uimgsize5)
ustat6 = uimgstream6.Read(uimgcontent6, 0, uimgsize6)
Dim ucmmdAs OleDbCommand =New OleDbCommand()
OleDbConnection1.Open()
Dim unp1AsNew OleDbParameter("@.uinput1", OleDbType.LongVarBinary)
unp1.Value = uimgcontent1
ucmmd.Parameters.Add(unp1)
Dim unp2AsNew OleDbParameter("@.uinput2", OleDbType.LongVarBinary)
unp2.Value = uimgcontent2
ucmmd.Parameters.Add(unp2)
Dim unp3AsNew OleDbParameter("@.uinput3", OleDbType.LongVarBinary)
unp3.Value = uimgcontent3
ucmmd.Parameters.Add(unp3)
Dim unp4AsNew OleDbParameter("@.uinput4", OleDbType.LongVarBinary)
unp4.Value = uimgcontent4
ucmmd.Parameters.Add(unp4)
Dim inp5AsNew OleDbParameter("@.input5", OleDbType.LongVarBinary)
inp5.Value = uimgcontent5
ucmmd.Parameters.Add(inp5)
Dim unp6AsNew OleDbParameter("@.uinput6", OleDbType.LongVarBinary)
unp6.Value = uimgcontent6
ucmmd.Parameters.Add(unp6)
If uimgname1 = ""Then
uimgname1 = "Nil"
Else
uimgname1 = File1.PostedFile.FileName
EndIf
If uimgname2 = ""Then
uimgname2 = "Nil"
Else
uimgname2 = File2.PostedFile.FileName
EndIf
If uimgname3 = ""Then
uimgname3 = "Nil"
Else
uimgname3 = File3.PostedFile.FileName
EndIf
If uimgname4 = ""Then
uimgname4 = "Nil"
Else
uimgname4 = File4.PostedFile.FileName
EndIf
If uimgname5 = ""Then
uimgname5 = "Nil"
Else
uimgname5 = File5.PostedFile.FileName
EndIf
If uimgname6 = ""Then
uimgname6 = "Nil"
Else
uimgname6 = File6.PostedFile.FileName
EndIf
If l1 <> "Nil"And l2 = "Nil"Then
uimgname1 = l1
uimgname3 = l3
uimgname4 = lw4
uimgname5 = lw5
uimgname6 = lw6
ucmmd.CommandText = "update [temp]set[input1]=@.uinput1,[name1]='" & uimgname1 & "',[input2]=@.uinput2,[name2]='" & uimgname2 & "',[input3]=@.uinput3,[name3]= '" & uimgname3 & "',[input4]=@.uinput4,[name4]= '" & uimgname4 & "',[input5]= @.uinput5,[name5]='" & uimgname5 & "',[input6]= @.uinput6,[name6]='" & uimgname6 & "' where [uid] = '" & ud & "'"
ElseIf l1 <> "Nil"And l2 <> "Nil"And l3 = "Nil"Then
uimgname1 = l1
uimgname2 = l2
ucmmd.CommandText = "update [temp]set[input1]=@.uinput1,[name1]='" & uimgname1 & "',[input2]=@.uinput2,[name2]='" & uimgname2 & "',[input3]=@.uinput3,[name3]= '" & uimgname3 & "',[input4]=@.uinput4,[name4]= '" & uimgname4 & "',[input5]= @.uinput5,[name5]='" & uimgname5 & "',[input6]= @.uinput6,[name6]='" & uimgname6 & "' where [uid] = '" & ud & "'"
ElseIf l1 <> "Nil"And l2 <> "Nil"And l3 <> "Nil"And lw4 = "Nil"Then
uimgname1 = l1
uimgname2 = l2
uimgname3 = l3
ucmmd.CommandText = "update [temp]set[input1]=@.uinput1,[name1]='" & uimgname1 & "',[input2]=@.uinput2,[name2]='" & uimgname2 & "',[input3]=@.uinput3,[name3]= '" & uimgname3 & "',[input4]=@.uinput4,[name4]= '" & uimgname4 & "',[input5]= @.uinput5,[name5]='" & uimgname6 & "',[input6]= @.uinput6,[name6]='" & uimgname6 & "' where [uid] = '" & ud & "'"
ElseIf l1 <> "Nil"And l2 <> "Nil"And l3 <> "Nil"And lw4 <> "Nil"And lw5 = "Nil"Then
uimgname1 = l1
uimgname2 = l2
uimgname3 = l3
uimgname4 = lw4
ucmmd.CommandText = "update [temp]set[input1]=@.uinput1,[name1]='" & uimgname1 & "',[input2]=@.uinput2,[name2]='" & uimgname2 & "',[input3]=@.uinput3,[name3]= '" & uimgname3 & "',[input4]=@.uinput4,[name4]= '" & uimgname4 & "',[input5]= @.uinput5,[name5]='" & uimgname5 & "',[input6]= @.uinput6,[name6]='" & uimgname6 & "' where [uid] = '" & ud & "'"
ElseIf l1 <> "Nil"And l2 <> "Nil"And l3 <> "Nil"And lw4 <> "Nil"And lw5 <> "Nil"And lw6 = "Nil"Then
uimgname1 = l1
uimgname2 = l2
uimgname3 = l3
uimgname4 = lw4
uimgname5 = lw5
ucmmd.CommandText = "update [temp]set[input1]=@.uinput1,[name1]='" & uimgname1 & "',[input2]=@.uinput2,[name2]='" & uimgname2 & "',[input3]=@.uinput3,[name3]= '" & uimgname3 & "',[input4]=@.uinput4,[name4]= '" & uimgname4 & "',[input5]= @.uinput5,[name5]='" & uimgname5 & "',[input6]= @.uinput6,[name6]='" & uimgname6 & "' where [uid] = '" & ud & "'"
EndIf
ucmmd.Connection = OleDbConnection1
ucmmd.ExecuteNonQuery()
OleDbConnection1.Close()
EndSub
EndSubI didnt' get any errors!
0 comments:
Post a Comment