Convert Access Query to VB.net SQL Statement -
i have table in access database called historical_stock_prices
filled various companies historical stock prices. need run query convert raw data (the stock prices) quarterly growth rates , display quarterly growth rates in datagridview
.
i've written the following query in sql view of access database , works within access.
select minmaxyrqtrdates.yrqtr, minmaxyrqtrdates.ticker, minmaxyrqtrdates.maxdate, [historical prices].close, minmaxyrqtrdates.mindate, [historical prices_1].open, ([historical prices].[close]/[historical prices_1].[open]-1)*100 growthrate [historical prices] [historical prices_1] inner join ([historical prices] inner join [select year([date]) & "-" & datepart("q",[date]) yrqtr, [historical prices].ticker, max([historical prices].date) maxdate, min([historical prices].date) mindate [historical prices] group year([date]) & "-" & datepart("q",[date]), [historical prices].ticker]. minmaxyrqtrdates on ([historical prices].date = minmaxyrqtrdates.maxdate) , ([historical prices].ticker = minmaxyrqtrdates.ticker)) on ([historical prices_1].ticker = minmaxyrqtrdates.ticker) , ([historical prices_1].date = minmaxyrqtrdates.mindate);
i need able call within program , display results in datagridview
. i've tried copy sql statement access , use sql statement in code doesn't work. don't errors, datagridview
blank. here code far:
imports system.io imports system.data.oledb public class historical_growth_rates_annual public tblname string = "historical_stock_prices" private sub historical_growth_rates_annual_load(sender object, e eventargs) handles mybase.load if (file.exists(nordeen_investing_3.databasename)) nordeen_investing_3.con.open() dim restrictions(3) string restrictions(2) = tblname dim dbtbl datatable = nordeen_investing_3.con.getschema("tables", restrictions) if dbtbl.rows.count = 0 messagebox.show("historical stock prices tables not exist in database. please update") else dim da oledbdataadapter = new oledbdataadapter("select minmaxyrqtrdates.yrqtr, minmaxyrqtrdates.ticker, minmaxyrqtrdates.maxdate, [historical_stock_prices].close1, minmaxyrqtrdates.mindate, [historical_stock_prices_1].open1, ([historical_stock_prices].[close1]/[historical_stock_prices_1].[open1]-1)*100 growthrate [historical_stock_prices] [historical_stock_prices_1] inner join ([historical_stock_prices] inner join [select year([date1]) & " - " & datepart('q',[date1]) yrqtr, [historical_stock_prices].ticker, max([historical_stock_prices].date) maxdate, min([historical_stock_prices].date) mindate [historical_stock_prices] group year([date1]) & " - " & datepart('q',[date1]), [historical_stock_prices].ticker]. minmaxyrqtrdates on ([historical_stock_prices].date = minmaxyrqtrdates.maxdate) , ([historical_stock_prices].ticker = minmaxyrqtrdates.ticker)) on ([historical_stock_prices_1].ticker = minmaxyrqtrdates.ticker) , ([historical_stock_prices_1].date = minmaxyrqtrdates.mindate);", nordeen_investing_3.con) 'create new dataset dim ds new dataset() 'fill datset da.fill(ds) 'attach dataset datagrid datagridview1.datasource = ds.tables(0) ds = nothing da = nothing nordeen_investing_3.con.close() end if else messagebox.show("database not exist. please update.") end if end sub end class
i'm stuck , use help! thanks!
you want vb.net code recreate same select
statement works in access. however, looking @ syntax highlighting vim, think may creating else. (it may creating string difference of 2 other strings: "string 1" - "string 2"
).
but whether or not guessed correctly, use string variable hold select
statement. print string console or write text file can examine actual statement you're giving db engine.
or save working query in access named query object , use query name vb.net code --- absolutely guarantee using same sql confirmed work in access.
Comments
Post a Comment