Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Total newb

Author  Topic 

Jimmy2136
Starting Member

2 Posts

Posted - 2012-04-06 : 21:54:26
Hi, I'm totally new to SQL and administration. I've been trying to fiddle and figure things out. I've read through a few different books so I understood a little more. I took an Access course but was told SQL is like Apples and oranges compared to Access, and it has been so far...I was able to create myself a fake database pretty easy, run queries for the information within my tables and such. I'm having trouble with a front end application for it though, for example I wanna make a form where someone could put in a new entry to multiple tables, example would be ... first name, last name (on a PERSON table), a department (on a DEPARTMENT table), and than a box to put in a manager number of whoever hired the person. The other issue, with a form, that I wanna do is allow it to run a custom query everytime. I was able to use visual basic on "click" and button and run the same query everytime. Is there a way to make something like "Search database for name beginning <user imput> and ending <user imput> ... what should I lookup/read/learn to be able to create some for of front end application?

I know this was lengthy and probably super confusing, but I'm trying to learn and just not really finding any good advice on where to begin.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-06 : 23:03:52
for front end application development you should be using some application language like VB,C# etc

For implementing search part you will execute queries/procedures against database from your application. The values from form will be passed as parameters to query and query will be like

SELECT * FROM PERSON WHERE name BETWEEN @Start AND @End

@Start and @End are parameters defined and they get their values from front end application

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Xiez
Starting Member

13 Posts

Posted - 2012-04-07 : 04:47:32
First of all, welcome to the world of database development :)

Getting started is the hardest part, so let's see if I can help you a little bit.

It's been a while since I've used VB, but I'll give it a shot.

To do basic database manipulation you have to do a few things. First of all, you have to declare a connection string. This is telling your application where the database is. You can go to http://www.connectionstrings.com to build a CS for you scenario. The way you do this in code is something like (pardon my rusty VB):

Dim con as new SqlConnection(<Your connection string will go here>)
Dim cmd as new SqlCommand("SELECT stuff FROM Table Where somestuff = otherstuff", con)

con.open()
cmd.execute[something] (There's a few different execute styles you can google, executescalar returns 1 field, executenonquery runs a stored procedure or something that doesn't return anything, or executereader which... you can look up, there's a little more involved with that one)
con.close()


That's the basic syntax for executing a sql command in VB, and a place to start.

As far a querying "starting with" and "ending with" stuff, that would use the sql "LIKE" command and the '%' wildcard. An example would be:

SELECT *
FROM Users
WHERE Name LIKE 'Xi%' OR Name LIKE '%ez'

A few things you'll want to research:

"INSERT INTO" sql statements. This seems like what you'll want to be doing on click events. Here's a code snippet I just made:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim cn As New SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;")
Dim cmd As New SqlCommand("INSERT INTO Persons VALUES (" & txtFirstName & ", " & txtLastName & ", " & txtDepartment & ", " & intManagerNumber & ")", cn)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()

End Sub




I hope this randomness makes sense to you. Good luck :)
Go to Top of Page

Jimmy2136
Starting Member

2 Posts

Posted - 2012-04-07 : 08:09:32
quote:
Originally posted by Xiez
I hope this randomness makes sense to you. Good luck :)



Honestly, it did. Just finishing up a tech school for networking and security but I've been trying to teach myself a little SQL and also web design. So I'm getting a basic understanding and atleast have a little more knowledge, esp for looking into C# and VB programming. Going to continue to teach myself, and hopefully master, SQL just so I can put in on my resume ... and for some reason it's been fun to learn.
Go to Top of Page
   

- Advertisement -