Display Table Records from AS400 to Visual Basic - vb.net

I'm trying to display the records from PYLEAVE table, but when I use this code, it shows error SQL0204, can someone help me?
Call takeconnectionas400()
conn.Close()
conn.Open()
adapter = New OleDbDataAdapter("select * from PRIMA.PYLEAVE", conn)
ds = New DataSet
adapter.Fill(ds, "PRIMA.PYLEAVE")
DGVAS400.DataSource = ds.Tables("PRIMA.PYLEAVE")
DGVAS400.ReadOnly = True

In DB2 for IBM i, the syntax for the table is not DBNAME.TABLENAME it is SCHEMA.TABLENAME In old AS/400 terminology, that is LIBRARY.FILE Have your IBM i administrator tell you what schema (library) the table is in and change your SELECT statement appropriately.
I don't know VB, but in JDBC you specify the database name in the connection string, not the SELECT statement.

Related

How to use variable (datatable) in sql command text to execute

I am new to Vertica and trying this in angular aspx page.
`con.Open();
cmd = con.CreateCommand();
cmd.Connection = con;
cmd.Parameters.Add(new VerticaParameter("#tblCustomers", table));
cmd.CommandText = "insert into customers select * from #tblCustomers";
cmd.ExecuteNonQuery();`
I have established the connection and inserted some fresh records too.
But Now I am trying to insert bulk records in my vertica database's table.
Something Same like SqlServer,
I have loaded my table data into "table" variable. Which is a datatable.
Is it possible to do like this ?? As I am getting some error
"
Incorrect syntax at or near $1"
customers and #tblCustomers both have same columns.
Thanks!
Setting aside whether or not you should do something like this, in the code that you've posted you're passing #tblCustomers as a parameter to the query, so it's going to treat it as a string value, not an object name in the query. You need to build the CommandText in your code without that as a parameter. Something like:
cmd.CommandText = "insert into customers select * from " & tableName
(Sorry if that syntax isn't quite right, but hopefully it gets across the point)
Some additional (and important) notes though:
Always use a column list when doing an INSERT. Use INSERT INTO MyTable (some_column, some_other_column) SELECT... not INSERT INTO MyTable SELECT...
NEVER use SELECT *. List out your column names.

R and MSSQL - communication with temp tables (table not found on channel)

I'm trying to update global temp table using RODBC in a following way:
library(RODBC)
channel <- odbcConnect("RDataSource", uid = "user", pwd = "password")
query <- "select * from ##TempTable"
table_data <- sqlQuery(channel, query)
# data frame creation
sqlUpdate(channel, data_frame, index = "id", verbose = TRUE, tablename = "##TempTable")
Select query executes well, but sqlUpdate is failed with error message:
"Error in odbcTableExists(channel, tablename) : ‘##TempTable’: table not found on channel"
I suppose that the reason of this error may be connected with using of '#' in the name of temp tables.
UPD: I'm getting the same error with sqlSave function. This error occures only when I'm creating temp table, everything is ok with usual SQL tables.
Global temp table is creating before the calling of R code.
So, is there any way to communicate with temp tables in MSSQL database using R functions such as sqlSave() and sqlUpdate()?
I finally found that the cause of this error was in the settings of ODBC Data Source. It seems that communication with temp tables using R functions such as sqlSave or sqlUpdate requires the default database in ODBC data source to be set to 'tempdb'.
So, now I'm able to use sqlSave() function to insert values in temp table. This function in fact has much better performance than using sqlQuery function with the direct 'INSERT' query as a parameter.

OracleDataAdapter with GlobalTemporaryTable: FillSchema not working

I'm using FillSchema on a OracleDataAdapter in .net. The SelectCommand works on a global temporary table.
For the first run, this works great. I will get the schema of the global temporary table
Then I drop that temporary table and great a new temporary table with a different schema.
After that, for the second run, the FillSchema method will still return the schema from the old dropped temporary table.
Am I missing something? Shouldn't the select command query the schema from the new version of the temp table?
Thanks for any help!
What did not work:
The OracleDataAdapter.SelectCommand that was used by
FillSchema was:
Select * from TableName
What works:
I needed to change that query to the exact schema,
then it works:
Select column1,column2,column3 from TableName
I don't understand exactly why, but that solved my problem.
It will return the schema of the new global temporary table.
Is this a caching problem of the oracle server? Because the
tableName is always the same?
To use procedure ways to solve this Problem
OracleParameter inputParam = new OracleParameter("TABLE_NAME_IN",OracleDbType.Varchar2,"TEST",ParameterDirection.Input); //Query TableName
OracleParameter refParam = new OracleParameter("OUTPUT",OracleDbType.RefCursor,ParameterDirection.Output);//RefCursor
DataTable dt = new DataTable();//Fill DataTable
using (OracleCommand dbCommand = new OracleCommand("PKG_SYS.SELECT_TABLE_DATA",orclConnection))
{
dbCommand.CommandType = CommandType.StoredProcedure;
dbCommand.Parameters.Add(inputParam);
dbCommand.Parameters.Add(refParam);
using (OracleDataAdapter da = new OracleDataAdapter())
{
da.SelectCommand = dbCommand;
da.Fill(dt);
}
}

SQLite INNER JOIN with ATTACHed databases

I have two SQLite databases with identical table structures that I need to query using VB.Net, but I can figure out pretty much any syntax. I am trying to figure out how to build the query string? This query works correctly:
sb = New StringBuilder("SELECT Master.Name, Master.ID, Master.StartDate, Master.Supervisor, Log.LogType, Log.LogComment FROM Master INNER JOIN Log ON Master.ID = Log.ID WHERE date(Log.LogDate) = '")
sb.Append(calendarDate.ToString("yyyy-MM-dd"))
sb.Append("' ORDER BY Master.Name;")
c = New SQLiteCommand(sb.ToString, _Conn)
Using dr As SQLiteDataReader = c.ExecuteReader
...
I can also "attach" the second database with the following:
sb = New StringBuilder("ATTACH DATABASE '")
sb.Append(outDBPath)
sb.Append("' AS db2;")
c = New SQLiteCommand(sb.ToString, _Conn)
c.ExecuteNonQuery()
c.Dispose()
My question is, what is the syntax to query both databases? Is this even possible? In the past I used a For... Next loop and just changed the connection from the first database to the second.
http://www.sqlite.org/lang_attach.html:
Tables in an attached database can be referred to using the syntax
database-name.table-name. If the name of the table is unique across
all attached databases and the main and temp databases, then the
database-name prefix is not required. If two or more tables in
different databases have the same name and the database-name prefix is
not used on a table reference, then the table chosen is the one in the
database that was least recently attached.
So you use db2.Master to refer to the Master table in the attached database.

How to create database and add 2 table in SQLite

I am using SQLite ADO.NET Provider.
I want to create a database with 2 tables via code in vb.net .
Please provide code for the same.
I am using VS 2010 Winforms, working under XP SP3 Pro
Use the SQLiteConnection's CreateFile() method.
SQLiteConnection.CreateFile("c:\\mydatabasefile.db3")
More info on the System.Data.SQLite forums
You can then send ad-hoc CREATE TABLE statements to the engine:
dim myTableCreate as String =
"CREATE TABLE MyTable(CustomerID INTEGER PRIMARY KEY ASC,
FirstName VARCHAR(25));"
cmd.CommandText = myTableCreate
cmd.ExecuteNonQuery()
More on SQLite CREATE TABLE.
For those who need this, here is an updated working code...
SQLiteConnection.CreateFile("c:\mydatabasefile.db3")
Using Query As New SQLiteCommand()
Connection.ConnectionString ="DataSource=c:\mydatabasefile.db3;Version=3;New=False;Compress=True;"
Connection.Open()
With Query
.Connection = Connection
.CommandText = "CREATE TABLE MyTable(CustomerID INTEGER PRIMARY KEY ASC, FirstName VARCHAR(25))"
End With
Query.ExecuteNonQuery()
Connection.Close()
End Using