ms access 2013 - The Connection String Property Has Not Been Initialized vb.net -
please can tell me why database info not pulling through. fearly new vb , have been trying create project of google stuck on linking db
imports system.data.oledb public class myeventdb public shared function getevent(eventid integer) myevent dim myevent new myevent dim connection oledbconnection = myathleteevents.getconnection dim selectstatement string = "select eventid, title, date, fee, location, distance " & "from events " & "where eventid = @eventid" dim selectcommand new oledbcommand(selectstatement, connection) selectcommand.parameters.addwithvalue("@eventid", eventid) try connection.open() dim reader oledbdatareader _ = selectcommand.executereader(commandbehavior.singlerow) if reader.read myevent.eventid = cint(reader("eventid")) myevent.title = reader("title").tostring myevent.ddate = reader("date").tostring myevent.fee = reader("fee").tostring myevent.location = reader("location").tostring myevent.distance = reader("distance").tostring else myevent = nothing end if reader.close() catch ex exception throw ex connection.close() end try return myevent end function public shared function addevent(myevent myevent) integer dim connection oledbconnection = myathleteevents.getconnection dim insertstatement string = "insert events " & "(title, date, fee, location, distance) " & "values (@title, @date, @fee, @location, @distance)" dim insertcommand new oledbcommand(insertstatement, connection) insertcommand.parameters.addwithvalue("@title", myevent.title) insertcommand.parameters.addwithvalue("@date", myevent.ddate) insertcommand.parameters.addwithvalue("@fee", myevent.fee) insertcommand.parameters.addwithvalue("@location", myevent.location) insertcommand.parameters.addwithvalue("@distance", myevent.distance) try connection.open() insertcommand.executenonquery() dim selectstatement string _ = "select ident_current('events') events" dim selectcommand new oledbcommand(selectstatement, connection) dim eventid integer = cint(selectcommand.executescalar) return eventid catch ex exception throw ex connection.close() end try end function public shared function updateevent(oldevent myevent, newevent myevent) boolean dim connection oledbconnection = myathleteevents.getconnection dim updatestatement string = "update events set " & "title = @newtitle, " & "date = @newdate, " & "fee = @newfee, " & "location = @newlocation, " & "distance = @newdistance " & "where eventid = @oldeventid " & "and title = @oldtitle " & "and date = @olddate " & "and fee = @oldfee " & "and location = @oldlocation " & "and distance = @olddistance" dim updatecommand new oledbcommand(updatestatement, connection) updatecommand.parameters.addwithvalue("@newtitle", newevent.title) updatecommand.parameters.addwithvalue("@newdate", newevent.ddate) updatecommand.parameters.addwithvalue("@newfee", newevent.fee) updatecommand.parameters.addwithvalue("@newlocation", newevent.location) updatecommand.parameters.addwithvalue("@newdistance", newevent.distance) updatecommand.parameters.addwithvalue("@oldeventid", oldevent.eventid) updatecommand.parameters.addwithvalue("@oldtitle", oldevent.title) updatecommand.parameters.addwithvalue("@olddate", oldevent.ddate) updatecommand.parameters.addwithvalue("@oldfee", oldevent.fee) updatecommand.parameters.addwithvalue("@oldlocation", oldevent.location) updatecommand.parameters.addwithvalue("@olddistance", oldevent.distance) try connection.open() dim count integer = updatecommand.executenonquery if count > 0 return true else return false end if catch ex exception throw ex connection.close() end try end function public shared function deleteevent(myevent myevent) boolean dim connection oledbconnection = myathleteevents.getconnection dim deletestatement string = "delete events " & "where eventid = @eventid " & "and title = @title " & "and date = @date " & "and fee = @fee " & "and location = @location " & "and distance = @distance" dim deletecommand new oledbcommand(deletestatement, connection) deletecommand.parameters.addwithvalue("@eventid", myevent.eventid) deletecommand.parameters.addwithvalue("@title", myevent.title) deletecommand.parameters.addwithvalue("@date", myevent.ddate) deletecommand.parameters.addwithvalue("@fee", myevent.fee) deletecommand.parameters.addwithvalue("@location", myevent.location) deletecommand.parameters.addwithvalue("@distance", myevent.distance) try connection.open() dim count integer = deletecommand.executenonquery if count > 0 return true else return false end if catch ex exception throw ex connection.close() end try end function end class imports system.data.oledb public class myathleteevents public shared function getconnection() oledbconnection ' if necessary, change following connection string ' works system dim connectionstring new oledbconnection("provider=microsoft.ace.oledb.12.0;data source=c:\users\lebom\desktop\ict3611assignment\athletesevents.accdb") return new oledbconnection() end function end class
in myathleteevents.getconnection
, create 1 oledbconnection
object connection string then, instead of returning object, return second new oledbconnection
object.
this:
return new oledbconnection()
should this:
return connectionstring
that said, why use name 'connectionstring' variable of type oledbconnection
? it's not connection string why name though is? have string
connection string.
Comments
Post a Comment