472,353 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

VB.Net WindowsApplication Save Access Database Record

1
Friends,
I'm probably being more critical with VB.Net Windows application.
I have Developed VisualStudio 20005 VB.Net Windows application
how willl i be able to save a specific record into my database file throu GUI Save Record button?
As i write the comand as foloow but it is not inserting the new record in to the Access Database.

Public Function Open_Connection() As Boolean
Try
Select Case DBInfo(No).Database_Type
Case Database_Type.OracelDB
Select Case No
Case 0 : If Cn_Def.State = ConnectionState.Open Then Cn_Def.Close()
Cn_Def.ConnectionString = "Provider=MSDAORA.1;Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Data Source=" & DBInfo(No).Server_Name & ";"
Cn_Def.Open()
Case 1 : If Cn1.State = ConnectionState.Open Then Cn1.Close()
Cn1.ConnectionString = "Provider=MSDAORA.1;Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Data Source=" & DBInfo(No).Server_Name & ";"
Cn1.Open()
Case 2 : If Cn2.State = ConnectionState.Open Then Cn2.Close()
Cn2.ConnectionString = "Provider=MSDAORA.1;Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Data Source=" & DBInfo(No).Server_Name & ";"
Cn2.Open()
End Select

Case Database_Type.SQLServer
Select Case No
Case 0 : If Cn_Def.State = ConnectionState.Open Then Cn_Def.Close()
Cn_Def.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & DBInfo(No).Database_Name & ";Data Source=" & DBInfo(No).Server_Name & ";Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=" & DBInfo(No).Server_Name & ";Use Encryption for Data=False;Tag with column collation when possible=False"
Cn_Def.Open()
Case 1 : If Cn1.State = ConnectionState.Open Then Cn1.Close()
Cn1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & DBInfo(No).Database_Name & ";Data Source=" & DBInfo(No).Server_Name & ";Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=" & DBInfo(No).Server_Name & ";Use Encryption for Data=False;Tag with column collation when possible=False"
Cn1.Open()
Case 2 : If Cn2.State = ConnectionState.Open Then Cn2.Close()
Cn2.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & DBInfo(No).Database_Name & ";Data Source=" & DBInfo(No).Server_Name & ";Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=" & DBInfo(No).Server_Name & ";Use Encryption for Data=False;Tag with column collation when possible=False"
Cn2.Open()
End Select

Case Database_Type.AccessDB
Select Case No
Case 0 : If Cn_Def.State = ConnectionState.Open Then Cn_Def.Close()
Cn_Def.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBInfo(No).Database_Name
Cn_Def.Open()
Case 1 : If Cn1.State = ConnectionState.Open Then Cn1.Close()
Cn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBInfo(No).Database_Name
Cn1.Open()
Case 2 : If Cn2.State = ConnectionState.Open Then Cn2.Close()
Cn2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBInfo(No).Database_Name
Cn2.Open()
End Select
End Select
Return True
Catch ex As Exception
Select Case No
Case 0
If Cn_Def.State = ConnectionState.Open Then
Return True
Else : MsgBox(ex.Message)
If Not Loded Then
Lb_Name1 = "Access Database"
Dim X As New Connection_Frm
X.ShowDialog()
End If
Return False
End If
Case 1
If Cn1.State = ConnectionState.Open Then
Return True
Else : MsgBox(ex.Message)
If Not Loded Then
Lb_Name1 = "Access Database"
Dim X As New Connection_Frm

X.ShowDialog()
End If
Return False
End If
Case 2
If Cn2.State = ConnectionState.Open Then
Return True
Else : Msg = ex.Message
MsgBox(ex.Message, MsgBoxStyle.Critical, "Farm Manager")
If Not Loded Then
Lb_Name1 = "Database"
Dim X As New Connection_Frm
X.ShowDialog()
End If
Return False
End If
End Select
'Finally
End Try
End Function
End Module


Public Function Exec(ByVal CN As OleDb.OleDbConnection, ByVal Statement As String, _
ByVal ParamArray Param As Object()) As Boolean
Try
If CN.State = ConnectionState.Closed Then CN.Open()
Dim Cmd As New OleDb.OleDbCommand(Statement, CN)

Dim i As Integer
For i = 0 To Param.Length - 1
Cmd.Parameters.Add("Param" & i, Param(i))
Next
Cmd.ExecuteNonQuery()
Catch e As Exception
Dim i As Integer
Dim x As String = ""
For i = 0 To Param.Length - 1
x &= "Parameter(" & i & "): " & Param(i).ToString & vbCrLf
Next
MsgBox(e.Message, MsgBoxStyle.Critical)
Return False
Finally
End Try
Return True
End Function

SAVE BUTTON TRIGGER AS FOLLOWING


Private Sub Btn_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Save.Click
Dim sql As String

If Status Then
If Trim(Me.Txt_FISH_SEQ.Text) <> Nothing AndAlso IsNumeric(Me.Txt_FISH_SEQ.Text) Then
If Not Found_Prim("FISHING_TRANSACTIONS", "FISH_SEQ", Me.Txt_FISH_SEQ.Text) Then

CMDS.Exec(Cn_Def, "Insert into FISHING_TRANSACTIONS(Fish_Seq,Fish_Code,TRANSACTIO N_DATE,MARKET_CODE,QTY,WHOLSALE_PRICE,RETAIL_PRICE ,TOTAL_PRICE,NATURE,EXPORT,IMPORT) Values(?,?,?,?,?,?,?,?,?,?,?)", New Object() {Me.Txt_FISH_SEQ.Text, Me.Cmb_Fish_Code.Text, Me.DTP_FSHTRN_DAT.Text, Me.Txt_MKT_CODE.Text, Me.Txt_QTY.Text, Me.Txt_WHOLSALE_PRICE.Text, Me.Txt_RETAIL_PRICE.Text, Me.TXT_TOTAL_PRICE.Text, Me.TXT_NATURE.Text, Me.CHK_EXPORT.Text, Me.CHK_IMPORTED.Text})
Else : MsgBox("Record Exist"MsgBoxStyle.Information, Me.Text)
Me.Txt_FISH_SEQ.Focus()

Me.DTP_FSHTRN_DAT.Focus()
End If

End If
Else


CMDS.Exec(Cn_Def, "Update FISHING_TRANSACTIONS set FISH_SEQ=?,FISH_CODE=?,TRANSACTION_DATE=?,MARKET_C ODE=?,QTY=?,WHOLESALE_PRICE=?,RETAIL_PRICE=?,TOTAL _PRICE=?,NATURE=?,EXPORT=?,IMPORT=? Where FISH_SEQ=" & Me.Txt_FISH_SEQ.Text, New Object() {Me.Txt_FISH_SEQ.Text, Me.Cmb_Fish_Code.Text, Me.DTP_FSHTRN_DAT.Text, Me.Txt_MKT_CODE.Text, Me.Txt_QTY.Text, Me.Txt_WHOLSALE_PRICE.Text, Me.Txt_RETAIL_PRICE.Text, Me.TXT_TOTAL_PRICE.Text, Me.TXT_NATURE.Text, Me.CHK_EXPORT.Text, Me.CHK_IMPORTED.Text})

' Cmd_Cancel_Click(sender, e)
End If

End Sub
Mar 21 '07 #1
1 3607
vijaydiwakar
579 512MB
Friends,
I'm probably being more critical with VB.Net Windows application.
I have Developed VisualStudio 20005 VB.Net Windows application
how willl i be able to save a specific record into my database file throu GUI Save Record button?
As i write the comand as foloow but it is not inserting the new record in to the Access Database.

Public Function Open_Connection() As Boolean
Try
Select Case DBInfo(No).Database_Type
Case Database_Type.OracelDB
Select Case No
Case 0 : If Cn_Def.State = ConnectionState.Open Then Cn_Def.Close()
Cn_Def.ConnectionString = "Provider=MSDAORA.1;Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Data Source=" & DBInfo(No).Server_Name & ";"
Cn_Def.Open()
Case 1 : If Cn1.State = ConnectionState.Open Then Cn1.Close()
Cn1.ConnectionString = "Provider=MSDAORA.1;Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Data Source=" & DBInfo(No).Server_Name & ";"
Cn1.Open()
Case 2 : If Cn2.State = ConnectionState.Open Then Cn2.Close()
Cn2.ConnectionString = "Provider=MSDAORA.1;Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Data Source=" & DBInfo(No).Server_Name & ";"
Cn2.Open()
End Select

Case Database_Type.SQLServer
Select Case No
Case 0 : If Cn_Def.State = ConnectionState.Open Then Cn_Def.Close()
Cn_Def.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & DBInfo(No).Database_Name & ";Data Source=" & DBInfo(No).Server_Name & ";Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=" & DBInfo(No).Server_Name & ";Use Encryption for Data=False;Tag with column collation when possible=False"
Cn_Def.Open()
Case 1 : If Cn1.State = ConnectionState.Open Then Cn1.Close()
Cn1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & DBInfo(No).Database_Name & ";Data Source=" & DBInfo(No).Server_Name & ";Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=" & DBInfo(No).Server_Name & ";Use Encryption for Data=False;Tag with column collation when possible=False"
Cn1.Open()
Case 2 : If Cn2.State = ConnectionState.Open Then Cn2.Close()
Cn2.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=" & DBInfo(No).Database_Name & ";Data Source=" & DBInfo(No).Server_Name & ";Password=" & DBInfo(No).Password & ";User ID=" & DBInfo(No).User_Name & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=" & DBInfo(No).Server_Name & ";Use Encryption for Data=False;Tag with column collation when possible=False"
Cn2.Open()
End Select

Case Database_Type.AccessDB
Select Case No
Case 0 : If Cn_Def.State = ConnectionState.Open Then Cn_Def.Close()
Cn_Def.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBInfo(No).Database_Name
Cn_Def.Open()
Case 1 : If Cn1.State = ConnectionState.Open Then Cn1.Close()
Cn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBInfo(No).Database_Name
Cn1.Open()
Case 2 : If Cn2.State = ConnectionState.Open Then Cn2.Close()
Cn2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBInfo(No).Database_Name
Cn2.Open()
End Select
End Select
Return True
Catch ex As Exception
Select Case No
Case 0
If Cn_Def.State = ConnectionState.Open Then
Return True
Else : MsgBox(ex.Message)
If Not Loded Then
Lb_Name1 = "Access Database"
Dim X As New Connection_Frm
X.ShowDialog()
End If
Return False
End If
Case 1
If Cn1.State = ConnectionState.Open Then
Return True
Else : MsgBox(ex.Message)
If Not Loded Then
Lb_Name1 = "Access Database"
Dim X As New Connection_Frm

X.ShowDialog()
End If
Return False
End If
Case 2
If Cn2.State = ConnectionState.Open Then
Return True
Else : Msg = ex.Message
MsgBox(ex.Message, MsgBoxStyle.Critical, "Farm Manager")
If Not Loded Then
Lb_Name1 = "Database"
Dim X As New Connection_Frm
X.ShowDialog()
End If
Return False
End If
End Select
'Finally
End Try
End Function
End Module


Public Function Exec(ByVal CN As OleDb.OleDbConnection, ByVal Statement As String, _
ByVal ParamArray Param As Object()) As Boolean
Try
If CN.State = ConnectionState.Closed Then CN.Open()
Dim Cmd As New OleDb.OleDbCommand(Statement, CN)

Dim i As Integer
For i = 0 To Param.Length - 1
Cmd.Parameters.Add("Param" & i, Param(i))
Next
Cmd.ExecuteNonQuery()
Catch e As Exception
Dim i As Integer
Dim x As String = ""
For i = 0 To Param.Length - 1
x &= "Parameter(" & i & "): " & Param(i).ToString & vbCrLf
Next
MsgBox(e.Message, MsgBoxStyle.Critical)
Return False
Finally
End Try
Return True
End Function

SAVE BUTTON TRIGGER AS FOLLOWING


Private Sub Btn_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_Save.Click
Dim sql As String

If Status Then
If Trim(Me.Txt_FISH_SEQ.Text) <> Nothing AndAlso IsNumeric(Me.Txt_FISH_SEQ.Text) Then
If Not Found_Prim("FISHING_TRANSACTIONS", "FISH_SEQ", Me.Txt_FISH_SEQ.Text) Then

CMDS.Exec(Cn_Def, "Insert into FISHING_TRANSACTIONS(Fish_Seq,Fish_Code,TRANSACTIO N_DATE,MARKET_CODE,QTY,WHOLSALE_PRICE,RETAIL_PRICE ,TOTAL_PRICE,NATURE,EXPORT,IMPORT) Values(?,?,?,?,?,?,?,?,?,?,?)", New Object() {Me.Txt_FISH_SEQ.Text, Me.Cmb_Fish_Code.Text, Me.DTP_FSHTRN_DAT.Text, Me.Txt_MKT_CODE.Text, Me.Txt_QTY.Text, Me.Txt_WHOLSALE_PRICE.Text, Me.Txt_RETAIL_PRICE.Text, Me.TXT_TOTAL_PRICE.Text, Me.TXT_NATURE.Text, Me.CHK_EXPORT.Text, Me.CHK_IMPORTED.Text})
Else : MsgBox("Record Exist"MsgBoxStyle.Information, Me.Text)
Me.Txt_FISH_SEQ.Focus()

Me.DTP_FSHTRN_DAT.Focus()
End If

End If
Else


CMDS.Exec(Cn_Def, "Update FISHING_TRANSACTIONS set FISH_SEQ=?,FISH_CODE=?,TRANSACTION_DATE=?,MARKET_C ODE=?,QTY=?,WHOLESALE_PRICE=?,RETAIL_PRICE=?,TOTAL _PRICE=?,NATURE=?,EXPORT=?,IMPORT=? Where FISH_SEQ=" & Me.Txt_FISH_SEQ.Text, New Object() {Me.Txt_FISH_SEQ.Text, Me.Cmb_Fish_Code.Text, Me.DTP_FSHTRN_DAT.Text, Me.Txt_MKT_CODE.Text, Me.Txt_QTY.Text, Me.Txt_WHOLSALE_PRICE.Text, Me.Txt_RETAIL_PRICE.Text, Me.TXT_TOTAL_PRICE.Text, Me.TXT_NATURE.Text, Me.CHK_EXPORT.Text, Me.CHK_IMPORTED.Text})

' Cmd_Cancel_Click(sender, e)
End If

End Sub
dear put ur Q in .net forum
insted of entire code simply put the code where u've the problem
Mar 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are...
1
by: waddley | last post by:
I have a client who wants to have Access ask to save changes anytime data is changed or added into the database. I'm not really an Access guy, I...
4
by: WJA | last post by:
I'm probably missing something here but I can't understand the following. When 2 users try to save a record with the same primary key (a number...
2
by: josephm | last post by:
Hello Group: My first post on the group.Hope I get a response. I have a modest Fire Insurance ACCES Db.Thanks to this group - for the code. A...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the...
2
by: Ian | last post by:
I am trying to save the current record on a form before opening a report, doesn’t sound to hard does it? The code on a buttons on click event goes...
2
by: Karl | last post by:
Using A2000 When I click the save icon in form design, Access closes immediately. No warning messges, nothing. This happens on only one form....
7
by: Neil | last post by:
Was working in A2003 and noticed that the Save Record item on the Records menu was not available when the record was not dirty. In A2000, Save...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.