vb.net - Selecting different connection strings for data gridview -
why not straight-forward? have 2 databases contain log-table each. have stored procedure extracts data table. have datagridview on windows form, , drop-down box select connection string respective databases. on selection of conn string, want change datagridview contain log messages in selected database. code:
select case cboconnection.text case "cp dev" logconnectionstring = "data source=sambar.gofast.com;initial catalog=cpdev;user id=gofastconfig;password=gofastdev;" case "cp live" logconnectionstring = "data source=sambar.gofast.com;initial catalog=cplive;user id=gofastconfig;password=gofastlive;" end select dim cmd new sqlcommand("dbo.getlogmessages") using con new sqlconnection(logconnectionstring) using sda new sqldataadapter() cmd.connection = con cmd.commandtype = commandtype.storedprocedure sda.selectcommand = cmd sda.fill(me.customerpulsedbdataset1) con.close() gridlog.datasource = me.customerpulsedbdataset1.tables(0) end using end using
first, don't see open connection. then, got bit side down...
using con new sqlconnection(logconnectionstring) con.open() using cmd new sqlcommand("dbo.getlogmessages", con) cmd.commandtype = commandtype.storedprocedure using da new sqldataadapter(cmd) ' need clear out old data before reloading if same ds instance used if me.customerpulsedbdataset1.tables.count > 0 me.customerpulsedbdataset1.tables.clear() end if da.fill(me.customerpulsedbdataset1) end using end using con.close() end using gridlog.datasource = me.customerpulsedbdataset1.tables(0)
should work every time
Comments
Post a Comment