System.IO.IOException: 'Bad file name or number' - vb.net

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

Related

How to reduce the number of if-else statements (e.g. avoid hardcoding values)? [duplicate]

This question already has answers here:
VBA Function Avoiding If Statements
(3 answers)
Closed 2 years ago.
How to do this without hardcoding every Jar version?
So, in every ElseIf, it checks the version, if it's (for example 1.2.5), then download the software accordingly, to the path selected by the user + \ + type + _ + version + .jar. The problem is that there are more versions (more than 30 I think) and I don't want to hardcode all of them.
If JarVer = "1.2.1" Or JarVer = "1.2.2" Or JarVer = "1.2.3" Or JarVer = "1.2.4" Then
My.Computer.Network.DownloadFile(
"https://assets.minecraft.net/1_2/minecraft_server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.2.5" Then
My.Computer.Network.DownloadFile(
"https://assets.minecraft.net/1_2_5/minecraft_server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.3.1" Then
My.Computer.Network.DownloadFile(
"https://launcher.mojang.com/v1/objects/d8321edc9470e56b8ad5c67bbd16beba25843336/server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.3.2" Then
My.Computer.Network.DownloadFile(
"https://launcher.mojang.com/v1/objects/82563ce498bfc1fc8a2cb5bf236f7da86a390646/server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
ElseIf JarVer = "1.4.2" Then
My.Computer.Network.DownloadFile(
"https://launcher.mojang.com/v1/objects/3de2ae6c488135596e073a9589842800c9f53bfe/server.jar",
Path + "\" + SW + "_" + JarVer + ".jar")
...
They have to be hardcoded somewhere unless you have a consistent pattern.
I would consider putting the list in a data table or dictionary, then looking up the url from the version.

token expression in flat file connection

I have loaded the variables in the format for example:
where produkt = 'Muj zivot2 R' and uraz = 'Uraz'
and I need the output in the file name to be:
Muj zivot2 R_Uraz
token worked for me, but it doesn't work in this case
" + TOKEN(" #[User::where] ","''",2) + "_" + TOKEN(" #[User::where] ","''",4) + "
You can use the following expression:
TOKEN(#[User::where],"'",2) + "_" + TOKEN(#[User::where],"'",4)
Output
Muj zivot2 R_Uraz

Print a variable

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)

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)+")"

SQL unable to cast object of type 'system.string' to type 'system.iformatprovider' error in vb.net

I am trying to run this Query in my VB Application but receive an error saying:
unable to cast object of type 'system.string' to type 'system.iformatprovider'
SQL = "insert into billing_pdf_archive (reseller_sequence, invoice_number, pdf, worddoc, csv_cdr_file, csv_services_file, sub_total, vat_amount, grand_total, invoice_type, directdebit) values ('" + reseller.ToString + "','" + invoice_number.ToString + "', '" + Replace(reseller_company_name + "-" + invoice_number + ".pdf", " ", "_") + "', '" + Replace(reseller_company_name + "-" + invoice_number + ".doc", " ", "_") + "', '" + Replace(reseller_company_name + "-" + invoice_number.ToString + "_CDR.xlsx", " ", "_") + "', '" + Replace(reseller_company_name + "-" + invoice_number.ToString + "_Services.xlsx", " ", "_") + "', " + total.ToString("F2") + ", " + vat_amount.ToString("F2") + ", " + grand_total.ToString("F2") + ", 'Month End Reseller', '" + customer_direct_debit + "')"
conn3.ConnectionString = "server=" + global_variables.web_server_ip + "; user id=" + global_variables.web_server_username + "; password=" + global_variables.web_server_password + "; database=" + global_variables.web_server_database + "; "
conn3.Open()
myCommand3.Connection = conn3
myCommand3.CommandText = SQL
myCommand3.ExecuteNonQuery()
conn3.Close()
This is not a complete answer but I'll post it as an answer so that I can post formatted code. If you do as suggested in the comments and write clean, readable code then it will become obvious where the issue is and how to fix it. When you have one line that does lots of different things then working out what on that line is causing an issue is all but impossible. You should use an XML literal for your SQL code, parameters for your values and a connection string builder, e.g.
Dim sql = <sql>
INSERT INTO MyTable
(
Column1,
Column2
)
VALUES
(
#Column1,
#Column2
)
</sql>
command.CommandText = sql.Value
command.Parameters.AddWithValue("#Column1", value1)
command.Parameters.AddWithValue("#Column2", value2)
Dim builder As New SqlConnectionStringBuilder
builder.DataSource = server
builder.InitialCatalog = database
connection.ConnectionString = builder.ConnectionString
Now you'll be able to see exactly what part of your code is causing the issue and, if you still can't solve it yourself, will be able to point out where the issue is to us instead of expecting us to read that dog's breakfast.