Hi there, I'm a bit of a newbie to vb express 2008 and need a bit of assistance please!
I have 3 tables in a database (Order, Personnel, Products) and need to be able to manipulate the data. I (think I) know the commands to use are SELECT ... FROM, INPUT, DELETE but I have no idea when it comes to establishing a connection to the database so that the data can be manipulated.
The various input data (such as surname, DOB etc) comes from various textboxes that I have created on a form and this is then transfered to variables from which I hope to enter into the database when a button is clicked.
I've been tearing my hair out over this so any help would be very much appreciated!
8 1448
basically you will need to establish a connection and then run a query against the database to return a set of data which you can then use as required
there are plenty of tutorials on the web , from a quick google this one looks pretty straight forward - Part 2 - Using ADO .NET - Access and OleDB
if you have specific questions on the code feel free to post but as with many other sites it is better if you try to work things out first and then ask about problems you experience with the code.
Could you specify what database are you using?
Rey Sean
sorry, I should have added -
I presume that you are using an SQL server and although the link I have given is for Access it is pretty much the same except for the connection strings
Hey thanks for the replies.
I'm using an SQL database that I have set up inside the IDE. The thing that currently confuses me is the use of the connection strings but I'm sure that more confusion will arise afterwards!
I'll have a read of the link and investigate further.
Edit: I've also stumbled upon a guide Link which I'll have a look at.
Thanks again :)
Ok having had a look at the guide I found I've come up with this: - Dim connection_string As String = "data source=C:\Documents and Settings\Home\Desktop\VB\Project\Database.sdf"
-
Dim db_con As SqlConnection
-
Dim sql_con As New SqlCommand
-
-
db_con = New SqlConnection(connection_string)
-
sql_con.Connection = db_con
-
sql_con.CommandType = CommandType.Text
-
sql_con.CommandText = "INSERT INTO PERSONNEL(Username, Password, First name, Surname, DOB, Start date, Status)""VALUES (@Username, @Password, @First name, @Surname, @DOB, @Start date, @Status)"
-
-
sql_con.Parameters.Add("@Employee ID", SqlDbType.NVarChar).Value = 4
-
sql_con.Parameters.Add("@Username", SqlDbType.NText).Value = username
-
sql_con.Parameters.Add("@Password", SqlDbType.NText).Value = password
-
sql_con.Parameters.Add("@First name", SqlDbType.NText).Value = first_name
-
sql_con.Parameters.Add("@Surname", SqlDbType.NText).Value = surname
-
sql_con.Parameters.Add("@DOB", SqlDbType.Date).Value = DOB
-
sql_con.Parameters.Add("@Start date", SqlDbType.Date).Value = start_date
-
sql_con.Parameters.Add("@Status", SqlDbType.NChar).Value = status
-
-
Try
-
db_con.Open()
-
sql_con.ExecuteReader()
-
db_con.Close()
-
Catch ex As Exception
-
-
End Try
-
However when I exit the program nothing has changed in the database. Does what I'm doing at the moment actually save the database once the data has been inserted?
Cheers
- "INSERT INTO PERSONNEL(Username, Password, First name, Surname, DOB, Start date, Status)""VALUES (@Username, @Password, @First name, @Surname, @DOB, @Start date, @Status)"
Don't you have a few too many " in your sql string?
They should only be around the sql string like so - "INSERT INTO PERSONNEL(Username, Password, First name, Surname, DOB, Start date, Status) VALUES (@Username, @Password, @First name, @Surname, @DOB, @Start date, @Status)"
Thanks for the tip, although I'm still not sure what to do to get it to save! I've replaced: - db_con.Open()
-
sql_con.ExecuteReader()
-
db_con.Close()
with - db_con.Open()
-
sql_con.ExecuteNonQuery()
-
db_con.Close()
but still no difference. :(
Edit: Ok having put a message box to open in the event of an exception it's come out with this:
Can anyone decipher that? Thanks again.
yea basically that error message is telling you that your server doesnt accept remote sql connections... is the server in your local network? changing the properties on the server to allow remote sql connections might do the trick, or it might be something else... either way im not necessarily the person to ask about fixing it, im not all that good at networking but i hope this helped
Sign in to post your reply or Sign up for a free account.
Similar topics
by: System |
last post by:
Hello All,
Redhat 9.0
Mysql 3.23.56 ==> Running
I want to upgarde to 4.0.13 but this is the error it says:
# rpm -Uvh MySQL-server-4.0.13-0.i386.rpm
warning: MySQL-server-4.0.13-0.i386.rpm: V3...
|
by: Stephen |
last post by:
I am trying to add some code to below to include a datatable and fill the
datatable. The reason for doing this is so as I can check to see whether
there are any rows returned by the stored...
|
by: Joe Feldman |
last post by:
This position is located in the South Bay Area in Northern California.
If you are interested please send me your resume in a word .doc so
that I can review it. If this does not look like a match,...
|
by: Cindy B |
last post by:
Please send your resume and position to Cindy@AtlanticResource.com! I
CAN NOT accept candidates that ARE OUTSIDE OF THE US! NO PHONE CALLS
PLEASE! Email your resume to me!
Position:SQL...
|
by: Wade |
last post by:
I would like to install the .Net 1.1 framework on a Web Server running W2K
to be able to run ASP.NET files, but I'm not sure where to find the files I
need for the .Net framework.
I have ".NET...
|
by: dingoatemydonut |
last post by:
The C99 standard states:
"In the abstract machine, all expressions are evaluated as specified
by the semantics. An actual implementation need not evaluate part
of an expression if it can deduce...
|
by: Steve |
last post by:
Hi,
I am sitting down to design our next set of internal apps. I would like to
approach this in a way that would allow me to break logical parts of the
application that handle specific tasks...
|
by: ultradiv |
last post by:
I have a VB.NET application partly built that produces an xml output (just a
file at present)
I have a .NET webserver and SQLserver 2000
I need to be able to send the xml to the webserver/database...
|
by: Ian Davies |
last post by:
Hello
I would appreciate some help from someone who has knowledge of working with
css, php javascript and how they interact.
Ive been working on a task for the last few days and have started to...
|
by: C_guy |
last post by:
Does anyone know of a (hopefully free) tool that can traverse a
project and determine which "#include"s are not needed or needed in
every .C file? This would be helpful in removing header...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |