ejemplos ejemplo create ms-access vb6

ejemplo - Insertar pedido a MS Access desde VB6



create table access sql (1)

Obtuve una de nuestras aplicaciones anteriores de VB para gestión de formación. Estaba escrita en VB6 y la base de datos es MsAccess. Cuando estoy usando esa aplicación, mientras guardo las sesiones de entrenamiento, todos los registros se guardan entre los registros anteriores (no en orden). No se agrega en la última fila. Y también la aplicación que busca los datos de la base de datos y los muestra en gridview. Por lo tanto, la pantalla final está en una forma no ordenada. Como los últimos datos que me agregaron usando el formulario, mostrando en algún lugar en la fila del medio. Cuando veo la tabla de la base de datos, todos los datos nuevos se agregan en filas intermedias. Aquí mostraré el código:

sql = "INSERT INTO TrAssignment (BatchID,Category,CourseNumber,CourseTitle,FromDate,ToDate,Duration,Location, Trainer, FixedCost,DefaultStudentCost) VALUES (''" & CStr(txtBatchid.Text) & "'',''" & CStr(cmbCrscategory) & "'',''" & CStr(sCourNo) & "'', ''" & CStr(sCourTitle) & "'',''" & SchfromDTPick.Value & "'',''" & SchtoDTPicker.Value & "'',''" & CStr(txtSchduration.Text) & "'',''" & cmbLocation & "'',''" & CStr(cmbTrainer) & "'',''" & CStr(Trim(txtFixedcost.Text)) & "'',''" & CStr(Trim(txtDefault.Text)) & "'')" rs.Open sql, conn, adOpenDynamic, adLockOptimistic

Y también el formato de fecha en la forma es como dd-mm-aaaa, para algunos registros la fecha se guarda en este formato exacto. Pero para algunos, el formato de fecha es como d / m / aaaa. Solo están buscando la fecha del control de fecha, no formateando en el código.


Su formato de fecha es incorrecto. En general, puede beneficiarse de esta función:

'' Converts a value of any type to its string representation. '' The function can be concatenated into an SQL expression as is '' without any delimiters or leading/trailing white-space. '' '' Examples: '' SQL = "Select * From TableTest Where [Amount]>" & CSql(12.5) & "And [DueDate]<" & CSql(Date) & "" '' SQL -> Select * From TableTest Where [Amount]> 12.5 And [DueDate]< #2016/01/30 00:00:00# '' '' SQL = "Insert Into TableTest ( [Street] ) Values (" & CSql(" ") & ")" '' SQL -> Insert Into TableTest ( [Street] ) Values ( Null ) '' '' Trims text variables for leading/trailing Space and secures single quotes. '' Replaces zero length strings with Null. '' Formats date/time variables as safe string expressions. '' Uses Str to format decimal values to string expressions. '' Returns Null for values that cannot be expressed with a string expression. '' '' 2016-01-30. Gustav Brock, Cactus Data ApS, CPH. '' Public Function CSql( _ ByVal Value As Variant) _ As String Const vbLongLong As Integer = 20 Const SqlNull As String = " Null" Dim Sql As String Dim LongLong As Integer #If Win32 Then LongLong = vbLongLong #End If #If Win64 Then LongLong = VBA.vbLongLong #End If Select Case VarType(Value) Case vbEmpty '' 0 Empty (uninitialized). Sql = SqlNull Case vbNull '' 1 Null (no valid data). Sql = SqlNull Case vbInteger '' 2 Integer. Sql = Str(Value) Case vbLong '' 3 Long integer. Sql = Str(Value) Case vbSingle '' 4 Single-precision floating-point number. Sql = Str(Value) Case vbDouble '' 5 Double-precision floating-point number. Sql = Str(Value) Case vbCurrency '' 6 Currency. Sql = Str(Value) Case vbDate '' 7 Date. Sql = Format(Value, " /#yyyy//mm//dd hh/:nn/:ss/#") Case vbString '' 8 String. Sql = Replace(Trim(Value), "''", "''''") If Sql = "" Then Sql = SqlNull Else Sql = " ''" & Sql & "''" End If Case vbObject '' 9 Object. Sql = SqlNull Case vbError '' 10 Error. Sql = SqlNull Case vbBoolean '' 11 Boolean. Sql = Str(Abs(Value)) Case vbVariant '' 12 Variant (used only with arrays of variants). Sql = SqlNull Case vbDataObject '' 13 A data access object. Sql = SqlNull Case vbDecimal '' 14 Decimal. Sql = Str(Value) Case vbByte '' 17 Byte. Sql = Str(Value) Case LongLong '' 20 LongLong integer (Valid on 64-bit platforms only). Sql = Str(Value) Case vbUserDefinedType '' 36 Variants that contain user-defined types. Sql = SqlNull Case vbArray '' 8192 Array. Sql = SqlNull Case Else '' Should not happen. Sql = SqlNull End Select CSql = Sql & " " End Function