Email address getting in encoded format DB - sql

I'm getting the email address in encoded format like "annie#h ꇟ|(ƓƓⲘ" and i'm catching it in a string then not able to store it in server database. So how do i decode it to normal email address. or not getting which type of Encoding is it(base64/ascii/ect..).and the column type is long varchar,
machine i'm using it windows xp. I'm pulling my hair out.
Please help..

i caught the answer but i'm not sure is this the right way to do.
Now I read the record from ADODB.Recordset instead of Dataset.
is this the right way to read data.
I don't know why Dataset give me the wired email address,But using Record set i solve the issue
Here is the code sample that i use now
Dim str_query = "select * from table"
Dim objRS= New ADODB.Recordset
objRS= Cn.Execute(str_query )
Do While Not objRS.EOF
For k = 0 To objRS.Fields.Count - 1
Debug.Print objRS(k).Name & ": " & objRS(k).Value
Next
Debug.Print "_____"
objRS.MoveNext
Loop
And previously I used code this
Dim str_query = "select * from table"
Dim objRS= New ADODB.Recordset
objRS= Cn.Execute(str_query )
Dim ds As DataSet = New DataSet()
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.Fill(ds, objRS, "my_table")
For Each dr As DataRow In ds.Tables("my_table").Rows
Next

Related

Importing CSV to datatable with SQL command, values over 5,000,000,000 are left out / blank

I have a .CSV file that im filling a datatable in my application with.
one of the cells is a number, for example: 5720358152
these values seem to be getting skipped and nothing is put into the datatable.
here is my code:
Dim csvFile As String = "I:\STOCK.csv"
Dim folder = "I:\"
Dim csvStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & folder & ";Extended Properties=""text;HDR=No;FMT=Delimited"";"
Dim csvSQL = "SELECT * FROM [STOCK.csv]"
Dim MyDT As DataTable
Using csvCn = New OleDbConnection(csvStr),
cmd As New OleDbCommand(csvSQL, csvCn)
Using da As New OleDbDataAdapter(cmd)
MyDT = New DataTable
da.Fill(MyDT)
End Using
End Using
StockTakeDGV.DataSource = MyDT
Here is a list of numbers that get left out.
5720358152
5720358150
5720358146
5720350121
5720324303
5720308119
5720308118
5720308115
5720308114
5720308110
5720308104
But these numbers are fine:
4021021135
4021021132
4021021126
1320203187
1320023154
at first i thought it might have been the number of digits but other numbers with this many digits work, but i assume it's more to do with the "type" of number and that the value exceeds the limitation of that number type.
how do i overcome this problem?

vb.net Loading Images from Access Database to DataTable?

So I have a MS Access Database with 1 table (Records) and 2 fields in it ("RecordID" (Number), which is the primary key, and "LowRes" (OLE Object) which is a low Resolution image). There are about 100 records.
I/m trying to load the Access Table into a DataTable (ID_Table) in VB.net.
Code so far:
Dim cnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=SBS2257_ID.accdb;"
Dim theQuery As String = "SELECT [RecordID], [LowRes] FROM [Records];"
Using CN As New OleDbConnection(cnString)
Dim command As New OleDbCommand(theQuery, CN)
Using objDataAdapter = New OleDbDataAdapter(command)
Dim ID_Table As New DataTable
CN.Open()
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
Dim picture As Image = Nothing
Using stream As New IO.MemoryStream(pictureData)
picture = Image.FromStream(stream)
objDataAdapter.Fill(ID_Table)
End Using
End Using
End Using
However the "DirectCast" command fails when I tell it to look at more then 1 field in my SQL statement with a datatype mismatch (if I just do [LowRes] it does not throw a error). However, I get stuck again when trying to apply the result to the table via the objDataAdapter, it doesnt fill the table with anything? I also notice that "picture" only contains the first image in the database.
I could put this database query in a function using "WHERE RECORDID=..." and loop it manually building the table returning "picture" each time, but Id like to avoid running a function 100 times, esp one that access a database.
Is it possible to read the whole database that contains images and just load it directly into a Datatable in one big swoop?
EDIT: So I got this to work:
Dim strConnection As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=SBS2257_ID.accdb;"
Dim strSQL As String = "SELECT [RecordID], [LowRes] FROM [Records];"
Using objConnection = New OleDbConnection(strConnection)
Using objCommand = New OleDbCommand(strSQL, objConnection)
Using objDataAdapter = New OleDbDataAdapter(objCommand)
Dim objDataTable As New DataTable("IDs")
objDataAdapter.Fill(objDataTable)
Return objDataTable
End Using
End Using
End Using
how ever when I go to view row 0, col 1 which should be the first LowRes image via a .ToString Useing this code:
Private Sub PrintValues(ByVal table As DataTable)
For Each row As DataRow In table.Rows
For Each col As DataColumn In table.Columns
MsgBox(row(col).ToString())
Next col
Next row
End Sub
It just displays "System.Byte[]". It knows its a Byte datatype, but how do I display that in a picturebox?
The ExecuteScalar() executes the query, and returns the first column of the first row in the result set returned by the query.
as your query is
Dim theQuery As String = "SELECT [RecordID], [LowRes] FROM [Records];"
the first column is RecordID which is not a Byte().
you can change your query as following:
Dim theQuery As String = "SELECT [LowRes] FROM [Records];"
or you have to use other methods to get data from the database
Dim strSql As String = "SELECT [RecordID], [LowRes] FROM [Records]"
Dim dtb As New DataTable
Using cnn As New OleDbConnection(connectionString)
cnn.Open()
Using dad As New OleDbDataAdapter(strSql, cnn)
dad.Fill(dtb)
End Using
cnn.Close()
End Using

Unwanted data truncating from Excel

When I try to do an import from an Excel document the comments get truncated. I have checked the usually issue that the Table would be limited but is set as:
Comments ... nvarchar(MAX)
Sample of the code, please note even running the code in Debug mode I can see the parameter is truncated before it even goes to the stored procedure.
Dim excelConnectionString As String = (Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=") & vFileNameFolder) + "; Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"
'#### Upload, Rename and save file
'#### Open Excel to Parse here
Dim ds As New DataSet
Dim oleda As New OleDbDataAdapter()
Dim cmdExcel As New OleDbCommand()
'#### End - Open Excel to Parse here
Dim vActionRef As String = ""
Try
Dim excelConnection As New OleDbConnection(excelConnectionString)
With cmdExcel
.CommandText = "Select * from [Portal$A1:BB9999]" 'Names we want to select and the name of the sheet
.CommandType = CommandType.Text
.Connection = excelConnection
End With
excelConnection.Open()
oleda = New OleDbDataAdapter(cmdExcel)
oleda.Fill(ds, "dataExcel")
If ds.Tables("dataExcel").Rows.Count > 0 Then
'#### Stored procedure details
Dim connection As SqlConnection
Dim commandSQL As New SqlCommand
Dim FRAUPRN As String = ""
Dim ConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("SQLLocal").ToString()
'########### End - Stored procedure details
'Set date once
Dim vDate As Date
vDate = DateTime.Now.AddDays(0)
connection = New SqlConnection(ConnectionString)
connection.Open()
'Dims for error handling and checking for invalid characters
Dim iImported As Integer
For j As Integer = 0 To ds.Tables("dataExcel").Rows.Count - 1 ' counted rows so loop through, ignores first row with names in
If (IsDBNull(ds.Tables("dataExcel").Rows(j)("UPRN"))) Then
'skip
Else
iImported = iImported + 1
'Bring the data across, the rows(i)("xxx") must match a name on the Excel sheet but DOES NOT have to be in order
With commandSQL
.Parameters.Clear()
.Connection = connection
.CommandText = "spAddCSVDataLine" 'Stored procedure here
If Trim(ds.Tables("dataExcel").Rows(j)("Comments")) = "0" Then
.Parameters.AddWithValue("Comments", " ")
Else
' .Parameters.AddWithValue("Comments", If(IsDBNull(ds.Tables("dataExcel").Rows(j)("Comments")), "", Trim(ds.Tables("dataExcel").Rows(j)("Comments"))))
Dim vComments As String
vComments = ds.Tables("dataExcel").Rows(j)("Comments")
.Parameters.AddWithValue("Comments", vComments)
Session.Item("Comments") = Session.Item("Comments").ToString & "//" & vComments
End If
I have looked at similar questions such as ADO is truncating Excel data which talks about numerical issues but am struggling to find the reason why I am losing data before I export the data. 'Common sense' says excel is not passing over more than 255 characters but then this is programming!
I've had all sorts of problems with the JET/Ace DB engine truncating and doing other sorry-ass guesses at data type. Check out this Microsoft article that talks a bit about how JET uses only the first 8 records to determine field length (http://support.microsoft.com/kb/189897/en-us). You can edit a registry setting to change how many records it will scan to determine field length, but the results still seem to be hit or miss for folks.
You might also find some luck in creating a dummy record at the top of the excel sheet that contains a comment with the maximum number of characters of any of your comments. Then just delete that one record after it comes through. Again... results seem to be mixed here.

query sql database for specific value in vb.net

I am trying to convert VBA code to vb.net, im having trouble trying to search the database for a specific value around an if statement. any suggestions would be greatly appriciated.
thedatabase is called confirmation, type is the column and email is the value im looking for. could datasets work?
Function SendEmails() As Boolean
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim intResponse As Integer
Dim confirmation As New ADODB.Recordset
Dim details As New ADODB.Recordset
On Error GoTo Err_Execute
Dim MyConnObj As New ADODB.Connection
Dim cn As New ADODB.Connection()
MyConnObj.Open( _
"Provider = sqloledb;" & _
"Server=myserver;" & _
"Database=Email_Text;" & _
"User Id=bla;" & _
"Password=bla;")
confirmation.Open("Confirmation_list", MyConnObj)
details.Open("MessagesToSend", MyConnObj)
If details.EOF = False Then
confirmation.MoveFirst()
Do While Not confirmation.EOF
If confirmation![Type] = "Email" Then
' Create the Outlook session.
objOutlook = CreateObject("Outlook.Application")
' Create the message.
End IF
If you want really convert your code to NET then I think you should remove the ADODB objects and use the System.Data.SqlClient classes. Of course some things are more difficult now because the ADO.NET really use a detached model to work with databases.
The semi-equivalent of your code using the ADO.NET classes
....
' Use Try/Catch not the On Error Goto....'
Try
Dim conStr = "Server=myserver;Database=Email_Text;User Id=XXXX;Password=XXXXX;"
Using MyConnObj = new SqlConnection(conStr)
' Getting all the details rows and columns, '
' but you should select only the columns needed here....'
Using cmdDetails = new SqlCommand("SELECT * FROM MessagesToSend", MyConnObj)
' You need only the rows with Type=Email, so no need to retrieve all the rows'
Using cmdConfirm = new SqlCommand("SELECT * FROM Confirmation_list " & _
"WHERE [Type] = 'EMail' ", MyConnObj)
MyConnObj.Open
Using da = new SqlDataAdapter(cmdConfirm)
Dim dt = new DataTable()
da.Fill(dt)
Using reader = cmdDetails.ExecuteReader()
While reader.Read()
For Each row in dt.Rows
... ' The Outlook app should be instanced outside the loop'
Next
Loop
End Using
End Using
End Using
End Using
End Using
Catch x As Exception
MessageBox.Show("Error:" & x.Message)
End Try
Possibly the usage of the Type column is causing an issue. You might be able to get this working by doing the following:
confirmation.Fields("Type").Value
instead of
confirmation![Type]
but I would recommend you look into ADO.NET isntead of using ADODB as this is quite old now.

How to use 2 connection objects while importing data from one database to another in vb.net

I am using the following code to select from one database and need to insert into another database.. Please suggest me the code:
Code :
'Connection for Original database from where i have to import
Dim constrOrg As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strPath
Dim conn_OrgDB As New OleDb.OleDbConnection(constrOrg)
'Connection for my database to where i have to import
Dim App_Path = System.AppDomain.CurrentDomain.BaseDirectory()
Dim constr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App_Path + "Mydb.accdb"
Dim cnnOLEDB As New OleDb.OleDbConnection(constr)
Dim strSelInv_one As String = ("SELECT * FROM INV_ONE where (DOCU_DT>=#stdt AND DOCU<=#enddt) ")
Dim comm_inv_one As OleDb.OleDbCommand = New OleDb.OleDbCommand(strSelInv_one, conn_OrgDB )
comm_inv_one.Parameters.AddWithValue("#stdt", StTime)
comm_inv_one.Parameters.AddWithValue("#enddt", Endtime)
dr = comm_inv_one.ExecuteReader
Do While dr.Read = True
Dim strInsInv1 As String = "INSERT INTO INVOICE_ONE(CODE_NO,LAY,..) SELECT CODE_NO,LAY,... FROM INV_ONE where (CODE_NO=#code)"
Dim comm_Insinv1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(strInsInv1, cnnOLEDB)
comm_Insinv1.Parameters.AddWithValue("#code", Code_no)
comm_Insinv1.ExecuteNonQuery()
Loop
'Here INVOICE_ONE table belongs cnnOLEDB connection obj of one database and INV_ONE table belongs to conn_OrgDB connection object of another database..
' How to use the 2 connection object ? If i use only one connection object i.e. cnnOLEDB it gives the following Error:
" The Microsoft Office Access database engine cannot find the input table or query 'INV_ONE'. Make sure it exists and that its name is spelled correctly. "
Please suggest me the code..
Thank you
try this code, obviously don't make it as long as his ( basically wack out stuff you don't need and imput your code, now ....
in addition to :
Dim connectionStr = Constants.Input.MDB.CONNECTION_STRING & _
"Data Source=" & dbFullPath & ";"
Dim connection As New System.Data.OleDb.OleDbConnection(connectionStr)
in addition use
Dim connectionStr2 = "Other conection string"
Dim connection2 As New System.Data.OleDb.OleDbConnection(connectionStr)
and import it into his code.
link:
Selecting data in MS Access with vb.net is very slow. Am I doing it right?
I am sorry if this won't help, since i don't have an access db i cannot further test this.
Reguards.
My suggestion would be use to Access to create Linked Tables in the target database that point to the corresponding tables in the source (production) database. Then you can at least manipulate both sets of tables using the same connection, thereby giving you the option of doing
INSERT INTO INVOICE_1 (codeno, lchlndt, ...)
SELECT codeno, lchlndt, ... FROM INV_ONE ...