Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
whenever tried it executing but cannot update database.

What I have tried:

VB
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim sqlconn As New OleDb.OleDbConnection
            Dim sqlquery As New OleDb.OleDbCommand
            Dim connString As String
            connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\PrMas.accdb"
            sqlconn.ConnectionString = connString
            sqlquery.Connection = sqlconn
            sqlconn.Open()
            sqlquery.CommandText = "INSERT INTO Project(ProjectName,Abstract,SemesterCreated,AuthorName) VALUES (@projectname,@abstract,@semestercreated,@authname)"
            sqlquery.Parameters.AddWithValue("@projectname", txtProjectName.Text)
            sqlquery.Parameters.AddWithValue("@abstract", txtAbstract.Text)
            '  cmd.Parameters.AddWithValue("@creationDate", Convert.ToDateTime(DPCreationDate.Value.ToString))
            sqlquery.Parameters.AddWithValue("@semestercreated", CBSemCreated.Text)
            'cmd.Parameters.AddWithValue("@addeddate", DateTime.Now)
            sqlquery.Parameters.AddWithValue("@authname", txtAuthorName.Text)
            Dim a As Integer
            a = sqlquery.ExecuteNonQuery()
            If a > 0 Then
                MessageBox.Show("New User successfully added.")

            Else
                MessageBox.Show("Try Again")
            End If
            sqlconn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
Posted
Updated 17-Jan-17 1:43am
v3
Comments
Richard MacCutchan 17-Jan-17 5:44am    
How are you checking the results?
RajkumarGnanaraj 17-Jan-17 5:53am    
i opened database nothing was there
Richard MacCutchan 17-Jan-17 6:15am    
Are you sure you are checking the correct file? I have used similar code to what you have above and it works correctly.
Maciej Los 17-Jan-17 7:07am    
As Richard mentioned, you have to check the path to the database. See: Where is DataDirectory ?[^]
Ashwin. Shetty 17-Jan-17 6:27am    
Can you check DataDirectory value and check the file path you verifying from. Also check if data file is getting redeployed at every build The code seems to be ok to me.

1 solution

Can you check DataDirectory value and check the file path you verifying from. Also check if data file is getting redeployed at every build The code seems to be ok to me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900