本文介绍了无法在数据库中添加记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,程序员在这里遇到了一个小问题,如您所见,我想在数据库中添加一条记录(同一所大学,相同的代码,但中心不同).因此,当我单击提交"按钮时,有2条记录被保存在数据库中. />例如.
Hello programmers, got a small problem here as you see i want to add a records on the database(same college, same code but different in centers).So when I click submit button 2 records are saved in my database
EX.
i put text on textboxes Hidden variables of centers
college = wew 123
code = wew 456
centers = (based on hidden variables)
SUBMIT
And when I look on the database
College Code Center
wew wew 123
wew wew 456
多数民众赞成在我想要的,但有一个问题.当我点击提交"按钮时发生错误Invalid object name ''tblTraningPlan''.
指向command.executenonquery
请帮我..我忘了什么吗?
谢谢和更多强大的程序员
我的代码:
thats what i want, but got a problem. When I hit submit button an error occursInvalid object name ''tblTraningPlan''.
pointing at command.executenonquery
Plss help me.. Did I forgot something?
Thanks and more power programmers
MY CODES:
Imports System.Math
Imports System.Web
Imports System.Data.SqlClient
Imports System.Data
Partial Class Gee51
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
databind15029()
databind12934()
End Sub
Public Sub databind15029()
Dim strSQL As String
Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "INSERT INTO tblTraningPlan(CostCenter, College, Category, CourseCode, CourseTitle, Duration) VALUES (@CostCenter, @College, @Category, @CourseCode, @CourseTitle, @Duration)"
connection.Open()
Dim command As New SqlCommand(strSQL, connection)
command.Parameters.Add("@CostCenter", SqlDbType.NVarChar).Value = lbl15029.Text
command.Parameters.Add("@College", SqlDbType.NVarChar).Value = txtCollege.Text
command.Parameters.Add("@Category", SqlDbType.NVarChar).Value = lblGEE.Text
command.Parameters.Add("@CourseCode", SqlDbType.NVarChar).Value = txtCCode.Text
command.Parameters.Add("@CourseTitle", SqlDbType.NVarChar).Value = txtCT.Text
command.Parameters.Add("@Duration", SqlDbType.NVarChar).Value = txtDuration.Text
command.ExecuteNonQuery()
connection.Close()
End Sub
Public Sub databind12934()
Dim strSQL As String
Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "INSERT INTO tblTraningPlan(CostCenter, College, Category, CourseCode, CourseTitle, Duration) VALUES (@CostCenter, @College, @Category, @CourseCode, @CourseTitle, @Duration)"
connection.Open()
Dim command As New SqlCommand(strSQL, connection)
command.Parameters.Add("@CostCenter", SqlDbType.NVarChar).Value = lbl12934.Text
command.Parameters.Add("@College", SqlDbType.NVarChar).Value = txtCollege.Text
command.Parameters.Add("@Category", SqlDbType.NVarChar).Value = lblGEE.Text
command.Parameters.Add("@CourseCode", SqlDbType.NVarChar).Value = txtCCode.Text
command.Parameters.Add("@CourseTitle", SqlDbType.NVarChar).Value = txtCT.Text
command.Parameters.Add("@Duration", SqlDbType.NVarChar).Value = txtDuration.Text
command.ExecuteNonQuery()
connection.Close()
End Sub
End Class
推荐答案
这篇关于无法在数据库中添加记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!