|
anyway i have done it! thank you i was trying to let you understand me!
I am Entry level person
|
|
|
|
|
I have 2 tables (banks and rates) prepared in access database and these tables are connected through inner join.
The bank columns are (bankID and bankname) and Rates columns are (RateID, bankID, Monthnumber, CommissionRate).
I want to make a table on which I want display only the Bankname and the MonthNumber with Commissionrate related with this (bankID). When there is a change with the commission rate I should be able to update it on this table. If a bank should be added I should also be able to add or delete Bank and MonthNumber and Commissionrate accordingly. To sum up, I want to apply insert - update and delete operations on database which filled in datagrid.
I thank in advance to those who can help me.
|
|
|
|
|
I am encrypting some text using RC2 encryption in the database.
Encryption works fine.
Problem is decrypting it. When i try to decrypt it, it is throwing bad data exception.
Can anyone help?
|
|
|
|
|
Well, you can have about 100 things wrong. Your problem can be in your encryption and/or decryption code or in the database save/retrieve code. Without seeing any of this stuff, it's impossible to tell you what's wrong.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here is the Encrypt and Decrypt functions
Public Sub New()
mobjCrypto = New RC2CryptoServiceProvider
'//Generate the key. //
mobjCrypto.GenerateKey()
'// Assign the key to the byt variable. //
bytCryptoKey = mobjCrypto.Key
'// Generate a random initialization vector (IV) to be used for the algorithm. //
mobjCrypto.GenerateIV()
bytCryptoIV = mobjCrypto.IV
'// Prepare the Encryptor and Decryptor objects. //
mCryptoEncryptor = mobjCrypto.CreateEncryptor(bytCryptoKey, bytCryptoIV)
mCryptoDecryptor = mobjCrypto.CreateDecryptor(bytCryptoKey, bytCryptoIV)
mobjCrypto.Mode = CipherMode.CBC
End Sub
Public Function Encrypt(ByVal TextToEncrypt As String) As String
Dim strEncryptedData As String
Dim bytEncryptedData As Byte()
Dim bytPlainText As Byte()
Try
'// Create the memory stream. Encryption process will take place here instead of writing into a file. //
Dim msEncrypt As MemoryStream = New MemoryStream
'// Convert the text into byte form in preperation to be encrypted. //
bytPlainText = mTextConverter.GetBytes(TextToEncrypt)
'// Create the CryptoStream that ties together the MemoryStream and the ICryptoTransform. //
Dim csEncrypt As CryptoStream = New CryptoStream(msEncrypt, mCryptoEncryptor, CryptoStreamMode.Write)
'// Write the bytPlainText out to the CryptoStream and flush it. //
csEncrypt.Write(bytPlainText, 0, bytPlainText.Length)
'// Flush the CryptoStream so that nothing remains in the buffer. //
csEncrypt.Flush()
'// close the CryptoStream
csEncrypt.Close()
'// Get the encrypted text from the MemoryStream .I can't simply just grab the string because the stream doesn't work that way. //
bytEncryptedData = msEncrypt.ToArray()
'// Close the MemoryStream. //
msEncrypt.Close()
'// Convert the EncryptedDataBytes array into a base64 string. i.e. into a readable format. //
strEncryptedData = System.Convert.ToBase64String(bytEncryptedData)
Return (strEncryptedData)
Catch ex As Exception
Dim intExceptionNumber As Integer
End Try
End Function
Public Function Decrypt(ByVal EncryptedText As String) As String
Dim bytEncryptedData As Byte()
Dim bytDecryptedData As Byte()
Dim strDecryptedText As String
Try
'// Convert EncryptedText into a byte array to assign to the MemoryStream. //
bytEncryptedData = System.Convert.FromBase64String(EncryptedText)
' Create the memory stream which will hold the decrypted text. //
Dim msDecrypt As MemoryStream = New MemoryStream(bytEncryptedData)
'// Create the CryptoStream that ties together the MemoryStream and the ICryptoTransform. //
Dim csDecrypt As CryptoStream = New CryptoStream(msDecrypt, mCryptoDecryptor, CryptoStreamMode.Read)
bytDecryptedData = New Byte(bytEncryptedData.Length) {}
'// Read the data out of the crypto stream. //
csDecrypt.Read(bytDecryptedData, 0, bytDecryptedData.Length)
'// Flush and close the CryptoStream. //
csDecrypt.Flush()
csDecrypt.Close()
'// Close the memory stream. //
msDecrypt.Close()
'// Convert the byte array back into a string. //
strDecryptedText = mTextConverter.GetString(bytDecryptedData)
Return (strDecryptedText)
Catch ex As Exception
Dim intExceptionNumber As Integer
End Try
End Function
I am storing data after encrypting it and after retrieving it from the database trying to decrypt it.
Now the problem is that when i try to decrypt it
csDecrypt.Read(bytDecryptedData, 0, bytDecryptedData.Length)
it give Bad data as exception
Where am i wrong?
|
|
|
|
|
nitin_ion wrote: bytDecryptedData = New Byte(bytEncryptedData.Length) {}
'// Read the data out of the crypto stream. //
csDecrypt.Read(bytDecryptedData, 0, bytDecryptedData.Length)
'// Flush and close the CryptoStream. //
csDecrypt.Flush()
csDecrypt.Close()
One of the parameters to csDecrypt.Read() is wrong. My guess is that bytDecryptedData.Length should be bytEncryptedData.Length.
...Steve
|
|
|
|
|
The problem is still the same.
My guess is that it has got to do something with the key. But what i wanted is symmetric encryption without any password key.
|
|
|
|
|
Hi nitin_ion,
The way you have set it up, you generate a new random Key every time you create an instance of the class. The result is that you will only be able to encrypt the text, as you need to use the same Key (and IV) to encrypt and decrypt.
Hope this helps
//LO
|
|
|
|
|
Hi I've been trying to add node the main branch of TreeView.I must do it in For.......Next.
I don't want to use this code.
TreeView1.Nodes(0).Nodes.Add("Main Branch")
TreeView1.Nodes(0).Nodes(0).Nodes.Add("1. Sub Branch")
TreeView1.Nodes(0).Nodes(0).Nodes(0).Nodes.Add("2. Sub Branch")
I'm waiting your help.
|
|
|
|
|
Store the result of the previous Add method and reuse it the next time. Something like
previousNode = TreeView1.Nodes(0).Nodes.Add("Main Branch")
For i = 0 to n
previousNode = previousNode.Nodes.Add( i.ToString() & "Sub Branch")
Next i
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Use Recursive Functions
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
For i As Short = 0 To 4<br />
TreeView1.Nodes.Add(i.ToString & ". MAIN NODE")<br />
AddNode(TreeView1.Nodes(i), 3, 1)<br />
Next<br />
End Sub<br />
<br />
Protected Sub AddNode(ByVal Node As TreeNode, ByVal SubNodeCount As Integer, ByVal Level As Integer)<br />
'Level is used to end function<br />
If Not Level > 3 Then<br />
For j As Short = 1 To SubNodeCount<br />
Node.Nodes.Add(j.ToString & ". SUB NODE LEVEL (" & Level & ")")<br />
AddNode(Node.Nodes(j - 1), 3, Level + 1)<br />
Next<br />
End If<br />
End Sub
-- modified at 3:28 Monday 24th October, 2005
|
|
|
|
|
How can I use RegEx to hightlight a word that matches in Richtextbox?
Dim myRegex As New Regex("home address|business address")
Dim matches As MatchCollection
Dim xMatch As Match
If myRegex.IsMatch(Me.RichTextBox1.Text) Then
MsgBox("it works")
me.RichTextBox1.SelectionFont = ?
Me.RichTextBox1.SelectionColor = ?
Else
MsgBox("it does not")
End If
End Sub
|
|
|
|
|
|
I want to dynamically create a crystal report from .net code. Is ist possible.
Actually i have 20 fields in a table and i want to give user the option to select the fields he wants to view. Then genrate the report on the fly.
is it possible.i searched internet but could not find anything useful. all i could find is the reports or template are generated at designtime with the feilds added on them. but i donot want that i want the report to be created dynamically on th fly with user selected fields. The problem is if i create a template with 20 feilds which will be fixed and user selects first and lastfield then the space between those feilds cannot be adjusted. it will be blank. is there any othe solution for this.
any help will highly appreciated.
Thanks
Monica
|
|
|
|
|
I am using PrintDocument to Preview and print my data.
I want the duplex printing (My printer supports it).
When I execute
e.HasMorePages = true;
in Print event of myPrintDocument object. It keeps on printing the pages and starts the printing right from the beginning of my code in Print Event
(I think it is recursive?)
Please help me.
-- modified at 12:00 Saturday 22nd October, 2005
|
|
|
|
|
"e.hasmorepages=TRUE" means re-raise PrintPage Event.
What u wantto do?
|
|
|
|
|
I just want to print the next page (and avoid recursion). Don't want to execute the Print_Page code again for the page I have already printed.
|
|
|
|
|
Use something like that at below . If u still have problem send email to me with sample what you did ,
Dim PageNumber As Integer = 1<br />
Dim PageCount As Integer = 5<br />
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage<br />
Select Case PageNumber<br />
Case 1 : PrintFirstPage(e.Graphics) : e.HasMorePages = True<br />
Case PageCount : PrintLastPage(e.Graphics) : e.HasMorePages = False<br />
Case Else : PrintOtherPages(e.Graphics) : e.HasMorePages = True<br />
End Select<br />
PageNumber += 1<br />
End Sub<br />
<br />
Protected Sub PrintFirstPage(ByVal g As System.Drawing.Graphics)<br />
'PRINT PAGE<br />
End Sub<br />
Protected Sub PrintOtherPages(ByVal g As System.Drawing.Graphics)<br />
'PRINT PAGE<br />
End Sub<br />
Protected Sub PrintLastPage(ByVal g As System.Drawing.Graphics)<br />
'PRINT PAGE<br />
End Sub
|
|
|
|
|
I want to know how to copy file using code vb.net
|
|
|
|
|
How abourt posting the code your using. How does source get assigned? How does does dest get assigned? You could keep asking this question, but if don't understand the basics, you'lre never going to understand the answers either.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I know how to assign the source and destanation address of the file
for ex
file test.txt located in c:\ I want to copy it in e:\
dim pth as string="c:\test.txt"
dim pth2 as string="e:\"
file.copy(pth.pth2)
it dosent work
AMR-CIS
|
|
|
|
|
Don't delete your previous messages please. It makes it hard to track the conversation and takes away information from people joining in later.
Well, without knowing the exception that's being thrown (if any, hint hint!), the 5 most common problems are:
1 - The source file spec doesn't exist.
2 - The source file is locked by another process and can't be opened for read.
3 - The destination spec doesn't exist.
4 - The destination file path already exists and your trying to overwrite a file without telling the Copy method to do so.
5 - You don't have the appropriate permissions to write to the destination folder.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Does VB have the @ for strings to show that there's no escaping going on ? Or does it work totally differently in VB ? I'm just wondering if his strings are actually containing what he thinks.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No. All strings in VB are considered literal. There's nothing to escape.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
dim pth as string="c:\test.txt"
dim pth2 as string="e:\test.txt"
system.IO.File.Copy(pth,pth2)
|
|
|
|