300 points seeking solutions? Inserting a database into a database! ? ? ?

xiaoxiao2021-03-06  112

Because I have to do an exam system now, when the exam is over, there are 4, 5 hundred people to pay the volume, and each volume has more than 100 records to insert. . . So there is a problem with concurrency! ? There will be a lot of people can't make a mistake! Therefore, I specially posted this, I hope that people can help the younger brother! Not very grateful!!!

During our usual development, you often insert data into the database, sometimes you might want to make many similar operations, such as inserting several data simultaneously with the same table in the database, i.e., inserting data.

Insert data into the database, you can insert a number of data once insert a trade database, improve the performance efficiency of the program, or reduce our workload.

Batch inserted data, you can use two methods.

First, use the transaction (Transaction)

'Define the function of executing bulk inserted data, arguments for the INSERT SQL statement

Sub Extractions (Byval Sqlstrlist As String ())

DIM CONN AS STRING =

"Provider = microsoft.jet.Oledb.4.0; data source = Tax.mdb"

DIM Trans as oledbtransaction = Nothing

Try

IF conn.state = connectionState.closed then

Conn.open ()

END IF

DIM CMD AS Oledbcommand = New OLEDBCommand ()

cmd.connection = conn

cmd.comMandType = CommandType.Text

Trans = conn.begintransaction ()

cmd.transaction = trans

DIM I as integer

For i = 0 to sqlstrlist.getupperbound (0)

CMD.CommandText = SQLSTRLIST (i) 'Value in parameter (array)

cmd.executenonquery ()

NEXT

TRANS.COMMIT ()

Catch ex as oledbexception

TRANS. ROLLBACK ()

FANLLY

CONN.CLOSE ()

END TRY

End Sub

Second, use dataset

Public Sub INSERT ()

'Establish a DataTable data source

DIM DT AS DATATABLE = New DataTable ()

DIM DR AS DATAROW

Dt.columns.add (New Datacolumn ("Name"))

DIM J AS INTEGER

For j = 0 to 10

DR = DT.NEWROW ()

DR (0) = "name" j.toString

Dt.Rows.Add (DR)

NEXT

DIM conn as string = "provider = microsoft.jet.Oledb.4.0; data

Source = Tax.mdb "

Conn.open ()

DIM myadapter as oledbdataadapter = new oleDataAdapter ()

.

DIM CMD AS OLEDBCOMMAND = New OLEDBCOMMAND ("Insert Into Table (Name)

VALUES (@name) ", conn)

cmd.Parameters.Item ("@ name"). SourceColumns = DT.COLUMNS ("name"). ColumnSnamemyAdapter.Update (DT)

CONN.CLOSE ()

End Sub

Using the above two methods, you can complete the data batch insertion data.

XML ...

Each person will form a corresponding XML file in the process of the client.

Learn: 9527 File Name: 9527.xml

After the submission is completed, use the cycle

Tell all XML write databases

First, a three-layer structural mode must be used.

My classmate is in the system of running a race, at a distance of about 5 minutes, about thousands of betting points, and there are hundreds of bets, and people use IBM. Intermediate technology, never have problems

The front desk is submitted to the middleware, then the middleware starts the thread queue waiting, as long as the reception is successful and the data is complete, the middleware returns the correct completion of the information, and the remaining work is delivered to the thread of the middleware.

In middleware, you can also generate an XML file for records that have not been written to the database to prevent data loss.

If you don't do it, use MSMQ. Once the client is submitted to the server, place the record in the queue, and then the server is inserted from the queue to the database from the queue when there is time.

COM is to solve this problem.

You look at this information, make the submitted part, and use the client to call.

All SME Microsoft's predecessors are better solved, including message queues, multi-threaded equivalents, etc., don't worry, huh, huh.

转载请注明原文地址:https://www.9cbs.com/read-101658.html

New Post(0)