Hi,
Could anybody help me please what's wrong with my SQL statement?
I have three tables in my database. I have a dataset and three tableAdapters and want to write the sql command string for retrieving the data from the database with the following requirements:
string comstring="SELECT NOVI.GBR, NOVI.AB, NALOG1.DATA, Min(NALOG1.POCKM) AS MinOfPOCKM, Max(NALOG1.KRAJKM) AS MaxOfKRAJKM, (Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA FROM (NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA
HAVING (((NOVI.GBR)>="1081" And (NOVI.GBR)<="1149") AND ((NOVI.AB)="1") AND ((NALOG1.DATA)=#10/31/2011#))";
Thanks in advance.
Loading
TulasiPosted Nov 10, 2011, 7:07 AM
string comstring="SELECT NOVI.GBR, NOVI.AB, NALOG1.DATA, Min(NALOG1.POCKM) AS MinOfPOCKM, Max(NALOG1.KRAJKM) AS MaxOfKRAJKM, (Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA FROM (NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA
HAVING (((NOVI.GBR)>='1081' And (NOVI.GBR)<='1149') AND ((NOVI.AB)='1') AND ((NALOG1.DATA)=#10/31/2011#))";
TulasiPosted Nov 10, 2011, 11:41 PM
OleDBDataAdapter oleDBDataAdapter1 = new OleDBDataAdapter (
"SELECT * FROM Customers; SELECT * FROM Orders", connection)
myAdapter.Fill(dsTables)
dsTables.Tables(0).TableName = "Customers")
dsTables.Tables(1).TableName = "Orders")
chk the below link
http://vb.net-informations.com/dataset/dataset-multiple-tables-sqlserver.htm
NelPosted Nov 10, 2011, 7:51 AM
OleDbDataAdapter
Should I define 3 different oledbdataadapters only with the fields I need from each of them respectively?
oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand(comstring, conn));TulasiPosted Nov 10, 2011, 7:29 AM
oleDBDataAdapter1.Fill(_dataset, table_name1);
oleDBDataAdapter2.Fill(_dataset, table_name2);
oleDBDataAdapter3.Fill(_dataset, table_name3);
NelPosted Nov 10, 2011, 7:25 AM
Now how to fill the dataset when there are three tables i.e. three tableadapters. What should I put for the table_name in the command below?
oleDBDataAdapter1.Fill(_dataset, table_name);
Thanks
NelPosted Nov 10, 2011, 7:01 AM
1081" And (NOVI.GBR)<="1149") AND ((NOVI.AB)="1") AND ((NALOG1.DATA)=#10/31/2011#))";
In fact I have a problem to retrieve data from the three tables using the dataset. I have this code
this.WindowState = FormWindowState.Maximized;
NOVITableAdapter noviTA = new NOVITableAdapter();
//this.NOVITableAdapter.Fill(this.dataSet1.NOVI);
noviTA.Fill(dataSet1.NOVI);
NALOG1TableAdapter nalogTA = new NALOG1TableAdapter();
nalogTA.Fill(dataSet1.NALOG1);
MAGACINTableAdapter magTA = new MAGACINTableAdapter();
magTA.Fill(dataSet1.MAGACIN);
string comstring="SELECT NOVI.GBR, NOVI.AB, NALOG1.DATA, Min(NALOG1.POCKM) AS MinOfPOCKM, Max(NALOG1.KRAJKM) AS MaxOfKRAJKM, (Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA FROM (NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA HAVING (((NOVI.GBR)>="1081" And (NOVI.GBR)<="1149") AND ((NOVI.AB)="1") AND ((NALOG1.DATA)=#10/31/2011#))";
conn.Open();
//odbcConnection1.Open();
OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand(comstring, conn));
OleDbCommand command1 = new OleDbCommand();
command1.Connection = conn;
command1.CommandText = comstring;
command1.ExecuteNonQuery();
conn.Close();
and at the end I have to fill the dataset as well.
Pravin GhadgePosted Nov 10, 2011, 6:51 AM