please I need help with basic ado.net save, basic syntax needed

G

Guest

I am having some problems with getting squgglie lines under stringbuilder and
ConfigurationSettings

what am I doing wrong, is this even close to working? help.
------------------------------------------------------------------------------------
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

Public Class Locations
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "


Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Save.Click


Dim mySQLConnection As New
SqlConnection(ConfigurationSettings.AppSettings("DSN"))
Dim strSQLCommand As New StringBuilder, mySQLCommand As SqlCommand
strSQLCommand = New StringBuilder
With strSQLCommand
.Append("INSERT INTO Locations (Loc_Name, Address, ContactName,
Phone) ")
.Append("VALUES ('" & txtName.Text & "', '" & txtAddress.Text &
"', '" & txtContactName.Text & "', '" & txtPhone.Text & "');")
End With
mySQLConnection.Open()
mySQLCommand = New SqlCommand(strSQLCommand.ToString, mySQLConnection)
mySQLCommand.ExecuteNonQuery()
mySQLConnection.Close()

End Sub
End Class
 
J

Jay Pondy

At the top of your source file:

Imports System.Text
Imports System.Configuration.ConfigurationSettings
 
G

Guest

thanks!!!
is this the basics I need to do a save, that is al i m trying to do is learn
how to do 1 succesful ado.net save
 
G

Guest

i get error , connection string has not been initialized? what is wrong. I am
sure the answer is simple since I am a newbie!!!!
also, this code i just put on a form , do I need to drag the table on form
and make data set and sql adapter and all that, r should this code work
alone? do I have to bind the text boxes in properties window. be kind, I am
new
 
J

Jay Pondy

You are getting your connection string from AppSettings("DSN") .

Do you have an application configuration file in your project?

If you do - what is the value of the key "DSN" that you are calling
for?

If you don't - check out the System.Configuration stuff in the Docs.

The code you have will work - you do not need to drag a table or
anything else on the form.
 
G

Guest

I am not sure about the application config file. how would I now, what would
it be called. is there easir way to make connection string. it is simply sql
server db on local machine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top