vb.net - Trying to build a custom CRM application using VB + MySQL -
so i'm first time poster, long time user of site. anytime have question, make sure come here first. anyway, i'm trying build crm application using existing mysql database , visual studio 2010 in vb. here's code have far, , i'm trying return results of mysql query list view, make when double clicks on row, it'll open account. here's code have far.
i've been working on several hours, appreciate if can me out. extreme noob @ vb, decent mysql.
imports mysql.data.mysqlclient public class mainwindow public sconnection new mysqlconnection private sub mainwindow_load(byval sender system.object, byval e system.eventargs) handles mybase.load if sconnection.state = connectionstate.closed sconnection.connectionstring = "server = localhost; userid = system; password =; database = system" sconnection.open() end if end sub private sub searchbtn_click_1(byval sender system.object, byval e system.eventargs) handles searchbtn.click, button1.click dim sqlquery string = "select * tblclients" dim sqladapter mysqldataadapter dim sqlcommand new mysqlcommand dim table new datatable dim integer sqlcommand .commandtext = sqlquery .connection = sconnection end sqladapter .selectcommand = sqlcommand .fill(table) end = 0 table.rows.count - 1 dataview .items.add(table.rows(i)("id")) .items(.items.count - 1).subitems .add(table.rows(i)("fname")) .add(table.rows(i)("lname")) .add(table.rows(i)("company")) .add(table.rows(i)("email")) .add(table.rows(i)("phone")) .add(table.rows(i)("state")) .add(table.rows(i)("zipcode")) end end next end sub end class
if can again, appreciate it.
missing new on mysqldataadapter
dim sqladapter new mysqldataadapter
this fix problem object reference not set.....
, but, should follow suggestion tim schmelter. never keep global connection around lifetime of form/application. disaster waiting happen (especially mysql seems more sensitive leaked connections)
private sub searchbtn_click_1(.....) handles searchbtn.click, button1.click using sconnection = new mysqlconnection(.......) using sqlcommand = new mysqlcommand("select * tblclients", sconnection) sconnection.open() using sqladapter new mysqldataadapter() dim table new datatable dim integer sqladapter .selectcommand = sqlcommand .fill(table) end ...... ' rest of code fills view' end using end using end using end sub
in way close , dispose connection, command , adapter after no more requires in case of exceptions. see using statement
Comments
Post a Comment