|
That is why it is recommended to create a connection in the method where you need it, and to wrap it in a using-block to ensure disposing. It might sound expensive to create a new connection-object, but it is not. Hunting for these kinds of bugs is however.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You attempt to execute an INSERT statement which specifies 23 columns, but only inserts 20 values.
That throws the "Number of query values and destination fields are not the same" exception.
Your code then fails to close the connection, so the next time you click the button, you get the "Not allowed to change the 'ConnectionString' property..." exception.
As the others have said, create your connection object inside the method, and wrap it in a Using block[^] to ensure that it is always disposed of properly.
Make sure your INSERT statement has the same number of parameter placeholders in the VALUES part as the number of columns in the INSERT INTO part.
There's no need to convert the Text property to a string, as it's already a string.
You can simplify adding the parameters by using the AddWithValue method.
You should avoid catching the general Exception type. Only catch the exceptions that you want to handle. In this case, System.Data.Common.DbException is the only one you want to catch.
Const ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database3.mdb"
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Const CommandText As String = "INSERT INTO Inquiry_Form([Date], [RefNo], [NameP], [Address], [Age], [PhoneNo], [MobileNo], [EmailAd], [ReferralQuestion], [Type_of_Unit], [Date_of_Purchase], [Purpose_of_Purchase], [Monthly_Income], [RName], [RAddress], [RMobileNo], [R2Name], [R2Address], [RMobileNo], [R2Name], [R2Address], [R2MobileNo], [AgentsName]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
Using connection As New OleDbConnection(ConnectionString)
Using cmd As New OleDbCommand(CommandText, connection)
cmd.Parameters.AddWithValue("Date", TextBox1.Text)
cmd.Parameters.AddWithValue("RefNo", TextBox2.Text)
cmd.Parameters.AddWithValue("NameP", TextBox3.Text)
cmd.Parameters.AddWithValue("Address", TextBox4.Text)
cmd.Parameters.AddWithValue("Age", TextBox5.Text)
cmd.Parameters.AddWithValue("PhoneNo", TextBox6.Text)
cmd.Parameters.AddWithValue("MobileNo", TextBox8.Text)
cmd.Parameters.AddWithValue("EmailAd", TextBox7.Text)
cmd.Parameters.AddWithValue("ReferralQuestion", ComboBox1.Text)
cmd.Parameters.AddWithValue("Type_of_Unit", ComboBox2.Text)
cmd.Parameters.AddWithValue("Date_of_Purchase", ComboBox3.Text)
cmd.Parameters.AddWithValue("Purpose_of_Purchase", ComboBox4.Text)
cmd.Parameters.AddWithValue("Monthly_Income", ComboBox5.Text)
cmd.Parameters.AddWithValue("RName", TextBox10.Text)
cmd.Parameters.AddWithValue("RAddress", TextBox11.Text)
cmd.Parameters.AddWithValue("RMobileNo", TextBox15.Text)
cmd.Parameters.AddWithValue("R2Name", TextBox12.Text)
cmd.Parameters.AddWithValue("R2Address", TextBox13.Text)
cmd.Parameters.AddWithValue("R2MobileNo", TextBox14.Text)
cmd.Parameters.AddWithValue("AgentsName", TextBox16.Text)
Try
connection.Open()
cmd.ExecuteNonQuery()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox8.Clear()
TextBox7.Clear()
TextBox10.Clear()
TextBox11.Clear()
TextBox15.Clear()
TextBox12.Clear()
TextBox13.Clear()
TextBox14.Clear()
TextBox16.Clear()
Catch ex As System.Data.Common.DbException
MsgBox(ex.Message)
End Try
End Using
End Sub
You should also give your controls meaningful names, rather than accepting the default names created by the designer. You might remember that TextBox11 is the "RAddress" now, but when you come back to this code in a few months, you'll be cursing yourself for leaving the controls with the default names!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi
you have wrong in fields names
[R2Name],[R2Address],[RMobileNo],[R2Name],[R2Address],[R2MobileNo]
it is repeated so you have error
|
|
|
|
|
Can anybody help me create VB Script that I can use to gather the NIC Card Configuration for a list of Servers and store the information into an Excel Spread Sheet.
The Servers will have multiple Network Cards in use and I require the IP, Subnet and Gateway for each one in use.
Any help greatly appreciated!!
|
|
|
|
|
And? What part of this are you having a problem with?
|
|
|
|
|
pls i need the procedure on how to read a 3D stl file in vb 2010 ,i have already loaded the Glcontrol on my window application form .am new to vb.net pls i need help .thank you all
|
|
|
|
|
You're asking about the functionality of a 3rd party library. The best for support on it and how to use is the vendor for the library, here[^].
|
|
|
|
|
In an existing vb.net 2010 desktop application, I would need to have 2 users share the same computer. Both users will run the same desktop application but have access to different files and folders on the network share. Each person will have their own unqiue config file to show what files they have access to.
Based upon what I have said, I have the following questions to ask:
1. Will I need separate installs of the application on the same computer? Part of the install process includes placing the app.config file in the correct location. If so, can you tell me what I need to do for the separate installs?
2. If I do not need separate installs, what should I do about the separate app.config files? Each person's config file will point to files they directly have access to. I do not want each person to access the other person's config file.
modified 13-Oct-15 13:11pm.
|
|
|
|
|
dcof wrote: Will I need separate installs of the application on the same computer? No, you can get the windows user name and then use that to allow/disallow certain access.
dcof wrote: Each person's config file will point to files they directly have access to. I do not want each person to access the other person's config file. If they are admins on the machine then they can get access to it. Otherwise, if they are not, then you can use the user's app_data folder or something like that. But, it sounds like you may want to encrypt the config file or use a sql database to store what they can access.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
The files are on a network share. Thus can you tell me how I can restrict access by user on a network share?
|
|
|
|
|
dcof wrote: how I can restrict access by user on a network share Not sure what you mean exactly, but you can just right-click folders and set permissions.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Thanks this solves my issue!
|
|
|
|
|
Good to hear.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
Good Morning to all,
My customer Need to touch Screen Applications,screen fully show to icon and touch to show sub group image icon.how to possible this procedure,i have used few buttons but i don't know load sql values to buttons,so please help me to all......
thanks
dha NAA
|
|
|
|
|
dha NAA wrote: load sql values to buttons What exactly does that mean? SQL values may be strings, numbers, BLOBs, etc. Buttons are GUI copntrols, so there is no direct correlation between the two.
|
|
|
|
|
We'll need a lot more info from you as to where you are stuck if we are to be able to help.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
What is it exactly you are trying to do? More information may be helpful. What have you accomplished so far?
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
In a current vb.net 2010 application, there is a dropdown list where the user selects who they are. From this list, the application knows what files are unique to the user.
In the past there was only one user. Now there is going to be 4 to 8 different users. The dropdown list is used to point to where the files are located for each user. This occurs since the user selects their individual names from the dropdown list and all the files uniquely start with the name of the person. In other words if the name Joe is selected then all the file names are Joe_file1,Joe_file2, etc.
The users are concerend that they will accidently update each others files. The users do not want to this to occur. This solution was determined by the previous programmer so each person could backup each other.
Thus I am trying to determine what a good solution would be.
Here is what I am thinking a good solution should be:
1. Change the application to determine what windows logon the person is using. Possibly the windows identity property could be used. This way the application will determine what files the user has access to.
2. Have another windows user created that basically has admin rights. This admin user logon would have access to all the users files. Basically when a person signs on with the windows admin user account, they would have to know what files they are trying to access.
|
|
|
|
|
1. I absolutely agree with point 1 - user should not be selecting their name from a list - open to abuse/security breaches etc.
2. I also agree that you should have an "admin" logon with access to everything.
In addition - How about also having a "delegates" list (I mean this in the English sense not the .NET sense) ... on the database have a table that maps each user to the other users whose files they are allowed to see and/or update ... similar to the way Outlook / Lotus Notes allows. Individual users should be able to configure who they will allow to see their files but a user may not "demand" the access by just picking a name of a list.
If UserA logs on they see their own files by default, but can pick another user from a list, that list only shows the list of users who have given that permission
|
|
|
|
|
You have a good suggestion. However each person has their own access 2013 database. Thus would I setup each person to point to their correct files using the Access 2013 database?
|
|
|
|
|
If they all have individual databases then that does complicate matters a little (I originally thought of a shared database) ... not sure how you are going to be able to grant access to other files that way
|
|
|
|
|
If Focus is on DataGridview if Escape key is pressed then set focus to textbox1
If Focus is not on DataGridview if Escape key pressed then i want to close the form
how do? please help me.
|
|
|
|
|
|
I have used this code to access the webcam of my laptop and it perfectly works, but once i try to open it in my tablet it just shows me a black screen, the same thing happen when i test the code with a PC that does not have a webcam!
ANY IDEAS?
Dim hCap As Long
Private Sub cmd4_Click()
Dim sFileName As String
Call SendMessage(hCap, wm_cap_set_preview, CLng(False), 0&)
With CDialog
.CancelError = True
.Flags = cdlOFNPathMustExist Or cdlOFNOverwritePrompt
.Filter = "Bitmap Picture(*.bmp)|*.bmp|JPEG Picture(*.jpg)|*.jpg|All Files|*.*"
.ShowSave
sFileName = .FileName
End With
Call SendMessage(hCap, WM_CAP_FILE_SAVEDIB, 0&, ByVal CStr(sFileName))
DoFinally:
Call SendMessage(hCap, wm_cap_set_preview, CLng(True), 0&)
End Sub
Private Sub Cmd3_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
End Sub
Dim hwdc As Long
Dim startcap As Boolean
Private Sub cmdCapture_Click()
Dim temp As Long
hCap = capCreateCaptureWindow("Take a Camera Shot", ws_child Or ws_visible, 0, 0, PicWebCam.Width, PicWebCam.Height, PicWebCam.hWnd, 0)
If (hwdc <> 0) Then
temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
startcap = True
Else
MsgBox ("No Webcam found")
End If
End Sub
Private Sub Cmd2_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Sub
Private Sub Form_Load()
cmd1.Caption = "Start &Cam"
cmd2.Caption = "&Format Cam"
cmd3.Caption = "&Close Cam"
cmd4.Caption = "&Save Image"
End Sub
|
|
|
|
|