473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Vb.net sql help needed

4
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!
Jan 6 '09 #1
8 1448
jg007
283 100+
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.
Jan 6 '09 #2
lotus18
866 512MB
Could you specify what database are you using?

Rey Sean
Jan 6 '09 #3
jg007
283 100+
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
Jan 6 '09 #4
Gmez
4
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 :)
Jan 11 '09 #5
Gmez
4
Ok having had a look at the guide I found I've come up with this:

Expand|Select|Wrap|Line Numbers
  1. Dim connection_string As String = "data source=C:\Documents and Settings\Home\Desktop\VB\Project\Database.sdf" 
  2.         Dim db_con As SqlConnection
  3.         Dim sql_con As New SqlCommand
  4.  
  5.         db_con = New SqlConnection(connection_string)
  6.         sql_con.Connection = db_con
  7.         sql_con.CommandType = CommandType.Text
  8.         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)"
  9.  
  10.         sql_con.Parameters.Add("@Employee ID", SqlDbType.NVarChar).Value = 4
  11.         sql_con.Parameters.Add("@Username", SqlDbType.NText).Value = username
  12.         sql_con.Parameters.Add("@Password", SqlDbType.NText).Value = password
  13.         sql_con.Parameters.Add("@First name", SqlDbType.NText).Value = first_name
  14.         sql_con.Parameters.Add("@Surname", SqlDbType.NText).Value = surname
  15.         sql_con.Parameters.Add("@DOB", SqlDbType.Date).Value = DOB
  16.         sql_con.Parameters.Add("@Start date", SqlDbType.Date).Value = start_date
  17.         sql_con.Parameters.Add("@Status", SqlDbType.NChar).Value = status
  18.  
  19.         Try
  20.             db_con.Open()
  21.             sql_con.ExecuteReader()
  22.             db_con.Close()
  23.         Catch ex As Exception
  24.  
  25.         End Try
  26.  
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
Jan 11 '09 #6
truezplaya
115 100+
Expand|Select|Wrap|Line Numbers
  1. "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

Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO PERSONNEL(Username, Password, First name, Surname, DOB, Start date, Status) VALUES (@Username, @Password, @First name, @Surname, @DOB, @Start date, @Status)"
Jan 12 '09 #7
Gmez
4
Thanks for the tip, although I'm still not sure what to do to get it to save! I've replaced:

Expand|Select|Wrap|Line Numbers
  1. db_con.Open()
  2. sql_con.ExecuteReader()
  3. db_con.Close()
with

Expand|Select|Wrap|Line Numbers
  1. db_con.Open()
  2. sql_con.ExecuteNonQuery()
  3. 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.
Jan 12 '09 #8
raids51
59
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
Jan 13 '09 #9

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

Similar topics

0
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...
8
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...
13
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,...
0
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...
3
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...
17
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...
5
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...
0
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...
28
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...
37
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...

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.