I'm a beginner to VB.net 2005. I've started creating a small database project by refering to some VB.net books. I've know the use of dataadapter, datareader, commandbuilder etc which are required to connect to the database. I'm using Microsoft SQL Server Database File (SqlClient) for my project. I've used the sqlreader to display the database onto the windows form controls. But i can't add the records to the database. When i run the program and add the records to the database it add those records only to the dataset but the changes are not reflected to the database. Here is the code which i used to update the database which does not work.

Dim myCommand As SqlCommand       
myCommand.CommandType = CommandType.Text
connlyrics.Open()
varid= TextBox6.Text
varname = TextBox7.Text
varaddr = TextBox8.Text
myCommand = New SqlCommand("Insert into Employee (empid, name, Addr) values ('" & varid & "','" & varname & "','" & varaddr & "')", conn)
myCommand.ExecuteNonQuery()
da.Update(ds, "EmpDataSet")
MessageBox.Show("New Row Inserted")
connlyrics.Close()

What are the changes to be made in the code.

My second question is that if this program works fine is it really possible to make a installation (setup) file of this project. Are there any changes to be made in the project code. The connection string is used to link the database file. My project uses the following connection string to link to the database.

conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Employee.mdf;Integrated Security=True"

Now if the setup file of this code is created and installed in another computer does it really work. Is there any modifications to be made in the connection string.


Can anynbody tell me the complete procedure (step by step) to make a complete database application software (using VB.vet and Microsoft SQL Server Database File) from the beginning (Creating a new project) till the end (setup file).

You need a Command Builder Object for the Update.

Let us say you got the data on a DataGridView and wish to make changes from the gridview which must be reflected abck into your database. Make a button for update and use the following code-

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim cmdbuilder As New Odbc.OdbcCommandBuilder(adp)

'adp is an instance of the Data Adapter
'I'm using odbc, you might be using SQLClient

Try
' ds is the dataset, i returns the number of records updated
i = adp.Update(ds, "table name")
MsgBox(i & " records Updated Successfully")


Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

You can create an installer for your application. For this, start a new project of type Setup and Deployment.

As for the connection string, you might want to make a 'login' form which is splashed before the application begins which asks for server and database and user credentials (to connect to DB)

Hope it helps

i m a final year engg. student of comp. science deptt. I want some ideas for my project in this year. Ideas in database(oracle) and vb.net are welcomed.

If you want a project that you can finish within a week or less, try to develop an application that can be used in your department to hold attendance and marks.

i.e Attendance Register and Marks Card kind of application

This article has been dead for over six months. Start a new discussion instead.