Print a variable - vba

At first please check this thread -> Adding a variable inside VLookUp
Still doesn't work..
End Sub

Just set the a different value for the temp-variable and the Label:
temp = "Temp" + MonthNameUpper + "''" + CStr(MonthView1.Year - 2000)
Label3 = "Temp" + MonthNameUpper + "'" + CStr(MonthView1.Year - 2000)

Try this line temp = "Temp" + MonthNameUpper + "'" + CStr(MonthView1.Year - 2000) instead temp = "Temp" + MonthNameUpper + "''" + CStr(MonthView1.Year - 2000)

Related

How to store the first N rows of the current record as an array vector?

I defined a table as follows:
syms = "A"
datetimes = 2021.01.01..2022.01.01
n = 200
t = table(take(datetimes,n) as trade_time, take(syms,n) as sym,take(500+rand(10.0,n), n) as price)
You can try the following script:
syms = "A"
datetimes = 2021.01.01..2022.01.01
n = 200
t = table(take(datetimes,n) as trade_time, take(syms,n) as sym,take(500+rand(10.0,n), n) as price)
dayNum = 3
tbName = "t"
def getLastNDay(tbName, dayNum){
colName = "price"
scripts = "update " + tbName + " set lastNPrice = fixedLengthArrayVector("
for(n in 1..(dayNum-1)){
scripts = scripts + "move(" + colName + "," + n + "),"
}
scripts = scripts +"move(" + colName + "," + dayNum + "))"
print(scripts)
runScript(scripts)
}
getLastNDay(tbName, dayNum)
Output:

System.IO.IOException: 'Bad file name or number'

I have this string and I am trying to write it with FileSystem.Write and I keep getting this error of 'Bad file name or number'.
sline = FormName + "|" + OrderNo + "|" + BatchNo + "|" + OpusOverlay + "|"
+ Overlay + "|" + Type + "|" + Numbered + "|" + NeedPDF +
Constants.vbCrLf;
FileSystem.Write(1, sline);
What could be the cause of this? Any push in the right direction would be greatly appreciated
An example of what Hans was referring
Using strw As StreamWriter = New StreamWriter(Path+file.ext)
strw.Write(sline)
End Using

Web2Py insert into database error

I am trying to make insert. This is my code:
db.define_table('orders',
Field('idProduct', type = 'integer'),
Field('quantity', type = 'integer'),
Field('idUser', type = 'integer'),
Field('status'),
Field('order_date'),
Field('product_price', type = 'integer'))
The SQL:
sql = "Insert into orders (idProduct,idUser,quantity,status,order_date,product_price) values "
sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," + str(quantity) + ",'cart','" + str(order_date)+ "," + str(product_price)+"')"
and I am getting following error:
<class 'sqlite3.OperationalError'> 5 values for 6 columns
I don't understand what is wrong, because if i remove product_price, everything is working.
Thanks.
You have extra quote before the last closing bracket. Remove it and it will fix the error:
sql = sql + "(" + str(idProduct) + "," + str(idUser) + "," +
str(quantity) + ",'cart','" + str(order_date)+ "," +
str(product_price)+")"

Inserting Identity values from dataset into table using table adapter VB.net

Is there any way to get the table adapter to insert the values already in the dataset I pass it when inserting new rows?
I am synchronising two databases and this would be useful.
Here is currently how I am trying to do it but it auto increments and creates new identity values.
Dim dAdapterConstraints As New SqlClient.SqlDataAdapter("SELECT * FROM " + Tablename, _oConn)
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(dAdapterConstraints)
builder.QuotePrefix = "["
builder.QuoteSuffix = "]"
dAdapterConstraints.InsertCommand = builder.GetInsertCommand
Dim insertcommandstr As String = dAdapterConstraints.InsertCommand.CommandText.Substring(0, dAdapterConstraints.InsertCommand.CommandText.IndexOf("(") + 1) + " [" + Primarykey + "], " + dAdapterConstraints.InsertCommand.CommandText.Substring(dAdapterConstraints.InsertCommand.CommandText.IndexOf("(") + 1, dAdapterConstraints.InsertCommand.CommandText.Length - (dAdapterConstraints.InsertCommand.CommandText.IndexOf("(") + 1))
insertcommandstr = insertcommandstr.Replace("#p1", "#po1, #p1")
dAdapterConstraints.InsertCommand.Parameters.Add("#po1", getdbtype(dataset.Tables(0).Columns(Primarykey).DataType), dataset.Tables(0).Columns(Primarykey).MaxLength, Primarykey)
insertcommandstr = "SET IDENTITY_INSERT [" + Tablename + "] ON " + insertcommandstr + " SET IDENTITY_INSERT [" + Tablename + "] OFF"
dAdapterConstraints.InsertCommand.CommandText = insertcommandstr
dataset.EnforceConstraints = False
' opens connection
'fills dataset with results
Try
For Each row As DataRow In dataset.Tables(0).Rows
row.SetAdded()
Next
dAdapterConstraints.Update(dataset)
Catch ex As Exception
_oConn.Close()
MsgBox("Could not execute query on server database," + ex.ToString + ";Updating and inserting")
Return False
End Try

Pass a SQL condition as a OleDb parameter

I have following code:
Dim executedCmd As OleDb.OleDbCommand = m_dbMgr.GetCommand()
executedCmd.CommandText = "select * from [Parameters] where "
Dim SQLcondition As String = String.Empty
For i As Integer = 0 To ParameterName.Count - 1
executedCmd.CommandText += "ParameterName = #parametername" + i.ToString() + " and ParameterValue #ParamaterCondition" + i.ToString() + " #ParameterValue" + i.ToString()
executedCmd.Parameters.AddWithValue("#parametername" + i.ToString(), ParameterName(i))
executedCmd.Parameters.AddWithValue("#ParameterValue" + i.ToString(), ParameterValue(i))
executedCmd.Parameters.AddWithValue("#ParamaterCondition" + i.ToString(), Condition(i))
Next
ParameterName, ParameterValue, ParameterCondition all are same length ArrayList, but the code does not work properly. I have verified all the variables have values.
When I run the code it reports a syntax error: "missing operations in query expression"
The problem is that ParameterCondition has values like ('>', '<', '=',.... some logical SQL operators).
Edit: How can I include conditions in parameters?
Add 1 = 1 after where to simplify building logical expression. Notice that all conditions added by AND logical operator. You can generate parameter name from columns name.
executedCmd.CommandText = "select * from [Parameters] where 1 = 1"
....
executedCmd.CommandText += " AND " + ParameterName(i) + " " + Condition(i) + " #" + ParameterName(i)
executedCmd.Parameters.AddWithValue("#" + ParameterName(i), ParameterValue(i))
ParameterCondition must all be binary operators.
The database engine would check the syntax of the SQL statement before it replaces the parameters with values. So somethinhg like "WHERE #p1 #p2 #p3" will not be parsed correctly.
Replace your condition with a string-expression e.g.
commandtext = parameterName + condition + " #p1"