Great! Now my csv file was found! However I got another error.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:
Line 16: command.Parameters.AddWithValue("@email", inputUser) Line 17: con.Open() Line 18: password = command.ExecuteScalar().ToString() Line 19: con.Close() Line 20: Label1.Text = password
I think this error means that no value was put into the variable "password". I replaced "pass" with made-up words and resulted in the same error. Does that mean it is not reading the column name "pass" on the fist line of csv file?
Here.s my vb code
Imports System.Data.OleDb
Partial Class register
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inputUser As String = "info@msn.com"
Dim password As String
Dim path As String = Server.MapPath(Request.ApplicationPath) & "test\data\"
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & path & "; Extended Properties='text; HDR=Yes; FMT=Delimited'")
Dim command As OleDbCommand = con.CreateCommand()
command.CommandText = "SELECT tel FROM wholesale.csv WHERE email = @email"
command.Parameters.AddWithValue("@email", inputUser)
con.Open()
password = command.ExecuteScalar().ToString()
con.Close()
Label1.Text = password
End Sub
End Class
zuke01
Member
21 Points
41 Posts
Re: How to search for a value in a csv file and return another value.
Jul 01, 2008 07:39 AM|LINK
Great! Now my csv file was found! However I got another error.
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 16: command.Parameters.AddWithValue("@email", inputUser)Line 17: con.Open()
Line 18: password = command.ExecuteScalar().ToString()
Line 19: con.Close()
Line 20: Label1.Text = password
I think this error means that no value was put into the variable "password". I replaced "pass" with made-up words and resulted in the same error. Does that mean it is not reading the column name "pass" on the fist line of csv file?
Here.s my vb code
Imports System.Data.OleDb
Partial Class register
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inputUser As String = "info@msn.com"
Dim password As String
Dim path As String = Server.MapPath(Request.ApplicationPath) & "test\data\"
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & path & "; Extended Properties='text; HDR=Yes; FMT=Delimited'")
Dim command As OleDbCommand = con.CreateCommand()
command.CommandText = "SELECT tel FROM wholesale.csv WHERE email = @email"
command.Parameters.AddWithValue("@email", inputUser)
con.Open()
password = command.ExecuteScalar().ToString()
con.Close()
Label1.Text = password
End Sub
End Class
My csv file contains.....
line1: name,company,address,tel,email,pass,hear
line2: zuke oshiro,apparel news,4705 Willo Brook Ave.,3234015117,zuke@zuke.us,mypassword,web