VWD 2008, intergrated SQL, VB.NET form to database

aueddonlineaueddonline Member Posts: 611 ■■□□□□□□□□
I have a website that's been made in Visual Web Developer 2008, What I want is a form with a submit button that will send the data collected to an integrated SQL database which is then displayed within a grid view elsewhere on the site.

I found this
How to Add Record in a Database Using ASP.Net 2.0 - .Net Articles & Samples

It gives some VB code behind. Here is my submit button handler


Imports System.Data
Imports System.Data.SqlClient



Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click

'Create Connection String
'Initlize all Database Varaibles
Dim DBConn As New SqlConnection("UID=YourID;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sample Database;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
Dim DBCmd As New SqlCommand
Dim DBAdap As New SqlDataAdapter
Dim DS As New DataSet
DBConn.Open()

Try

'Add Insert Statement
DBCmd = New SqlCommand("INSERT INTO UserRecord(UserName, ContactNumber, Address, Country) VALUES (@UserName, @ContactNumber, @Address, @Country)", DBConn)

'Add Database Parameters
DBCmd.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = txtName.Text
DBCmd.Parameters.Add("@ContactNumber", SqlDbType.NChar).Value = txtCNumber.Text
DBCmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = txtAddress.Text
DBCmd.Parameters.Add("@Country", SqlDbType.NVarChar).Value = ddlCountry.SelectedItem.Text
DBCmd.ExecuteNonQuery()
Response.Write("Your Record is Updated ")

'Set the value of DataAdapter
DBAdap = New SqlDataAdapter("SELECT * FROM table1", DBConn)
'Fill the DataSet
DBAdap.Fill(DS)
'Bind with GridView control and Display the Record
gvShowRecord.DataSource = DS
gvShowRecord.DataBind()

Catch exp As Exception
Response.Write(exp)
End Try
'Close Database connection
'and Dispose Database objects
DBCmd.Dispose()
DBAdap.Dispose()
DBConn.Close()
DBConn = Nothing

End Sub
End Class


In bold are the elements I've changed,

I have a SQL database called database1 with columns that match the variables in the code.

On pressing the submit button I get the error

Cannot open database "Sample Database" requested by the login. The login failed.
Login failed for user 'LENOVO-X200\edward'.

the account itself have full access to the website folder

But also Why is this user name being selected to connect to the database? And how can I get the connection/auth working?

I have MySQL 5.1 installed and SQL server 2008, I think 2008 was installed with VWD.
What's another word for Thesaurus?
Sign In or Register to comment.