Because images cannot be stored directly, the data stream method is used here. I am still confused about some terms in. NET. I am not professional, but I just started to learn VB6 code and then I used VB. NET. So now I only write some code, but I don't know how it works. Hi, I'm leaving for a question. Come back soon. It's not good.
Because images cannot be stored directly, the data stream method is used here. I am still confused about some terms in. NET. I am not professional, but I just started to learn VB6 code and then I used VB. NET. So now I only write some code, but I don't know how it works. Hi, I'm leaving for a question. Come back soon. It's not good.
Because images cannot be stored directly, the data stream method is used here. I am still confused about some terms in. NET. I am not professional,
I just started to learn some VB6 code and then used VB. NET. So now I only want to write some code, but I don't know how it works.
Sorry, I am leaving for my question. Come back soon!
Well, let's take a look at the storage and reading of images and sounds. Check the code.
'The code in this section is the code for inserting images and sounds. 'The first one is the image. The path is of course the image address. Picturebyte = My. computer. fileSystem. in ReadAllBytes (PicturePath) ', this is the sound. The voicepath is still the voice address Voicebyte = My. computer. fileSystem. readAllBytes (VoicePath) 'is used to write SQL statements. The difference is that in the past, a COMMAND parameter is used to assign values to str = New System. text. stringBuilder str. append ("insert into wordinfo ([PICTURE], [ENGLISHNAME], [CHINESENAME], [VOICE], [Class])") str. append ("VALUES (?,?,?,?,?) ") Cmd = New OleDb. oleDbCommand (str. toString, DBConnection) cmd. parameters. add (New OleDb. oleDbParameter) cmd. parameters (0 ). value = Picturebyte cmd. parameters. add (New OleDb. oleDbParameter) cmd. parameters (1 ). value = EnglishName cmd. parameters. add (New OleDb. oleDbParameter) cmd. parameters (2 ). value = ChineseName cmd. parameters. add (New OleDb. oleDbParameter) cmd. parameters (3 ). value = Voicebyte cmd. parameters. add (New OleDb. oleDbParameter) cmd. parameters (4 ). value = Classstring cmd. executeNonQuery () 'After the SQL statement is completed, DBConnection is executed. close () MsgBox ("Save OK", MsgBoxStyle. information)
Check whether the above code is simple? In this way, you can store the data in the database. Here I still use ACCESS for demonstration, and SQL and other things are simpler.
All right. If you don't want to talk about anything else, continue to implement the function. I will discuss other issues at the end.
Let's take a look at how to read and view the code. (Why is it a bit like a knife in martial arts? Oh)
Dim Englishname As String Dim Picturebyte () As Byte Dim Voicebyte () As Byte Dim stream As New ADODB. stream Englishname = Trim (SearchTBox. text) If Englishname <> "" Then DBConnection. connectionString = DB_CnStr () DBConnection. open () 'starts to query Dim SQL As New System. text. stringBuilder SQL. append ("SELECT * from wordinfo") SQL. append ("where englishname = '"). append (Englishname ). append ("'") Dim cmd As New Ol EDb. oleDbCommand (SQL. toString, DBConnection) Dim RS As OleDb. oleDbDataAdapter = New OleDb. oleDbDataAdapter (cmd) Dim DT As New DataTable RS. fill (DT) DBConnection. close () 'is displayed If DT. rows. count = 0 Then MsgBox ("No Record", MsgBoxStyle. critical, "Error") Exit Sub Else 'interface to initialize Modifybtn. enabled = True Deletebtn. enabled = True 'ishishnametbox. enabled = True ChineseNameTBox. enabled = True ClassTbox. Enabled = True InsertPicLinkLab. enabled = True InsertVoiceLinkLab. enabled = True TestLinkLab. enabled = True RecordLinkLab. enabled = True Printbtn. enabled = True SearchTBox. text = "" '. You can skip this step. The key is to show the image Picturebyte = DT. rows (0 ). item (1) PictureBox1.Image = Bitmap. fromStream (New IO. memoryStream (Picturebyte, True), True) EnglishNameTBox. text = DT. rows (0 ). item (2 ). toString ChineseNameTBox. text = DT. rows (0 ). item (3 ). toString ClassTbox. text = DT. rows (0 ). item (5 ). tostring' here is the extraction of the sound file. What I need to explain is that I have studied it for a long time (applying the lines of experts) and have not found a good method. 'It seems that I can only store the sound file first, then you can play a video or something like that. I don't know if I can play stream files directly. 'or there are other methods. I just thought of it. I will try it later. With stream. mode = ADODB. connectModeEnum. adModeReadWrite. type = ADODB. streamTypeEnum. adTypeBinary. open (). write (DT. rows (0 ). item (4 )). saveToFile ("c:/test.wav", ADODB. saveOptionsEnum. adSaveCreateOverWrite) End With VoiceTBox. text = "c:/test.wav" End If Else MsgBox ("English Name is empty", MsgBoxStyle. critical, "Error") End If
OK. In the above words, We have stored and read data. Do not say anything about other updates? I think everyone must be smarter than me.
I don't know if I can use the code in this way to help you understand these operation methods. I hope you can communicate with me and have contact information in my space.
In the end, I have to worry about it. In fact, files like images and sounds are too large, or if you use a lot of them in your program, do not store them directly in the database and use them independently.
Put them in a folder, and then you will save the addresses of these files to the database, which will be very reasonable and will not affect the performance of the database and program.
I will only introduce the performance of large projects. Okay, that's all. Thank you!