插入查询正确执行但未在database.executenonquery中显示返回1。 [英] Insert query executing properly but not showing in database.executenonquery returns 1.

查看:74
本文介绍了插入查询正确执行但未在database.executenonquery中显示返回1。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当尝试执行但无法更新数据库时。



我尝试过:



whenever tried it executing but cannot update database.

What I have tried:

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

推荐答案

您可以检查DataDirectory值并检查您验证的文件路径吗? 。还要检查是否在每次构建时重新部署了数据文件代码似乎对我来说没问题。
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.


这篇关于插入查询正确执行但未在database.executenonquery中显示返回1。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆