Page Language='vb' AutoEventWireup='false' Codebehind ...
******Question 2
Q2 p1
Your Name:
Your Email :
Target Email:
*****Q2a.asp
Enter a text file name with content of Email:
*****Q2b.asp
*****Question 3
***Q3.asp
*** Upload.asp
Following grades extracted from file
Store in the DataBase?
Yes
No
*** final.asp
0 Then
Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
'Response.Write("No of Files: " & Request.Files.Count)
Session("flpath") = SaveLocation
Try
File1.PostedFile.SaveAs(SaveLocation)
lblmsg.Text = "The file " & fn & " has been uploaded and length is: " & File1.PostedFile.ContentLength & " bytes"
Dim myfile As New System.IO.StreamReader(SaveLocation)
Dim oneLine As String
Dim myarray(4) As String
oneLine = myfile.ReadLine()
While (oneLine "")
Dim cellCtr As Integer
myarray = Split(oneLine, ",")
Dim tRow As New TableRow
For cellCtr = 0 To 4
Dim tCell As New TableCell
tCell.Text = myarray(cellCtr)
tRow.Cells.Add(tCell)
Next
Table1.Rows.Add(tRow)
oneLine = myfile.ReadLine()
End While
myfile.Close()
rad1.Visible = True
btndb.Visible = True
Catch Exc As Exception
lblmsg.Text = "Error: " & Exc.Message
End Try
Else
lblmsg.Text = "Please select a file to upload."
End If
End Sub
Private Sub btndb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndb.Click
If rad1.SelectedItem.Value() = "Yes" Then
Try
Dim SaveLocation As String = Session("flpath")
Dim myfile As New System.IO.StreamReader(SaveLocation)
Dim strConString As String = "Password=syedstud1234;Persist Security Info=True;User ID=syedstud;Initial Catalog=testsyed;Data Source=mssql.cs.mnsu.edu,1400"
Dim objSqlConn As New SqlConnection(strConString)
objSqlConn.Open()
Dim oneLine As String
Dim myarray(4) As String
oneLine = myfile.ReadLine()
While (oneLine "")
Dim strSQL As String
Dim fldCtr As Integer
myarray = Split(oneLine, ",")
strSQL = "Insert into tblgrade values('" & myarray(0) & "'"
For fldCtr = 1 To 4
strSQL += ", " & myarray(fldCtr)
Next
strSQL += ")"
Dim objSqlCommand = New SqlCommand(strSQL, objSqlConn)
objSqlCommand.ExecuteNonQuery()
oneLine = myfile.ReadLine()
End While
myfile.Close()
lblmsg.Text = "Data saved in the database."
rad1.Visible = False
btndb.Visible = False
Catch Exc As Exception
lblmsg.Text = "Error: " & Exc.Message
End Try
End If
End Sub
An alternative method in for Q3
****** HTML page
midq3v1
yes
no
*******Code Behind
Private al As New ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
Response.Write("No of Files: " & Request.Files.Count)
Try
File1.PostedFile.SaveAs(SaveLocation)
lblmsg.Text = "The file " & fn & " has been uploaded and length is: " & File1.PostedFile.ContentLength & " bytes"
Dim file As New System.IO.StreamReader(SaveLocation)
Dim oneLine As String
Dim myarray(4) As String
oneLine = file.ReadLine()
While (oneLine "")
myarray = Split(oneLine, ",")
al.Add(New grade(myarray(0), myarray(1), myarray(2), myarray(3), myarray(4)))
oneLine = file.ReadLine()
End While
file.Close()
DataGrid1.DataSource = al
DataGrid1.DataBind()
radlist.Visible = True
btndb.Visible = True
File1.Visible = False
Button1.Visible = False
Catch Exc As Exception
lblmsg.Text = "Error: " & Exc.Message
End Try
Else
lblmsg.Text = "Please select a file to upload."
End If
End Sub
Private Sub btndb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndb.Click
Similar to the previous way of solving
End Sub
*******grade Class File: grade.vb
Public Class grade
Private g_name As String
Private g_grade1 As Short
Private g_grade2 As Short
Private g_grade3 As Short
Private g_grade4 As Short
Public Sub New(ByVal Name, ByRef Grade1, ByVal Grade2, ByVal Grade3, ByVal Grade4)
g_name = Name
g_grade1 = Grade1
g_grade2 = Grade2
g_grade3 = Grade3
g_grade4 = Grade4
End Sub
Public Property Name() As String
Get
Return g_name
End Get
Set(ByVal Value As String)
g_name = Value
End Set
End Property
Public Property Grade1() As String
Get
Return g_grade1
End Get
Set(ByVal Value As String)
g_grade1 = Value
End Set
End Property
Public Property Grade2() As String
Get
Return g_grade2
End Get
Set(ByVal Value As String)
g_grade2 = Value
End Set
End Property
Public Property Grade3() As String
Get
Return g_grade3
End Get
Set(ByVal Value As String)
g_grade3 = Value
End Set
End Property
Public Property Grade4() As String
Get
Return g_grade4
End Get
Set(ByVal Value As String)
g_grade4 = Value
End Set
End Property
End Class
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- creating ada compliant word 2013 2016 documents
- html forms richland community college
- images and links including absolute and relative paths
- using the html bridge
- lab 10 notes advanced asp odbc database connectivity
- page language vb autoeventwireup false codebehind
- creating a fill able and accessible fields for forms
- understanding hyper text
- introduction to mvc