I want to insert data from User Input to DB (MySQL 2005) using stored proc and a report to show the data which has one parameter at a time to view information.
I've tried for almost 2 weeks on this by refer to other sites but still i got errors. These are my codes. - Imports System.Data.OleDb
-
Imports System.IO
-
Imports System.Data.Common
-
Imports System.Data
-
Imports System.Data.SqlClient
-
Imports System.Collections.Generic
-
Imports System.Collections
-
Imports Microsoft.Reporting.WebForms
-
-
Partial Public Class Exam
-
Inherits System.Web.UI.Page
-
---------------
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Dim StrSQL = ("SELECT CertExamID,MemberName,ExamName,ExamDate,ExamNo FROM ExamCertificate")
-
Dim ds = New DataSet
-
Dim connectionString As String = "Integrated Security=SSPI;Persist Security Info=true; Initial Catalog=ISM;Data Source=MY-ANASTASIA"
-
Dim connection As SqlConnection = New SqlConnection(connectionString)
-
connection.Open()
-
Dim da As New SqlDataAdapter(StrSQL, connectionString)
-
da.Fill(ds)
-
txtID.Text = ds.Tables(0).Rows(0).Item("CertExamID").ToString()
-
txtName.Text = ds.Tables(0).Rows(0).Item("MemberName").ToString()
-
txtExam.Text = ds.Tables(0).Rows(0).Item("ExamName").ToString()
-
txtDateExam.Text = ds.Tables(0).Rows(0).Item("ExamDate").ToString()
-
txtNo.Text = ds.Tables(0).Rows(0).Item("ExamNo").ToString()
-
'End If
-
-
Try
-
Console.WriteLine(connection.State.ToString())
-
Finally
-
connection.Close()
-
End Try
-
End Sub
-
-
----------
-
Public Sub InsertExam()
-
Dim StrSQL = "insert into ExamCertificate(CertExamID,MemberName,ExamName,ExamDate,ExamNo) values(" & (txtID.Text.Trim) & "," & (txtName.Text.Trim) & "," & (txtExam.Text.Trim) & "," & (txtDateExam.Text.Trim) & "," & (txtNo.Text.Trim) & ")"
-
Dim ds As New DataSet
-
Dim intCurrentIndex As Integer = 0
-
Dim connectionString As String = "Data Source=MY-ANASTASIA;Initial Catalog=ISM;Integrated Security=True"
-
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT CertExamID, MemberName, ExamName, ExamDate, ExamNo FROM ExamCertificate", connectionString)
-
Dim connection As SqlConnection = New SqlConnection(connectionString)
-
da.Fill(ds)
-
connection.Open()
-
-
Try
-
Dim command As SqlCommand = _
-
New SqlCommand("InsertExam", connection)
-
command.CommandType = CommandType.StoredProcedure
-
-
-
command.Parameters.Add("@CertExamID", SqlDbType.VarChar, 40, Me.txtID.Text)
-
command.Parameters.Add("@MemberName", SqlDbType.VarChar, 40, Me.txtName.Text)
-
command.Parameters.Add("@ExamName", SqlDbType.VarChar, 40, Me.txtExam.Text)
-
command.Parameters.Add("@ExamDate", SqlDbType.VarChar, 40, Me.txtDateExam.Text)
-
command.Parameters.Add("@ExamNo", SqlDbType.VarChar, 40, Me.txtNo.Text)
-
-
Console.WriteLine("Rows inserted: " + _
-
command.ExecuteNonQuery().ToString)
-
-
Catch ex As Exception
-
Console.WriteLine(ex.Message)
-
Throw
-
Finally
-
connection.Close()
-
End Try
-
End Sub
-
---------------
-
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave1.Click
-
Dim StrSQL = "insert into ExamCertificate(CertExamID,MemberName,ExamName,ExamDate,ExamNo) values(" & (txtID.Text.Trim) & "," & (txtName.Text.Trim) & "," & (txtExam.Text.Trim) & "," & (txtDateExam.Text) & "," & (txtNo.Text) & ")"
-
Dim ds As New DataSet
-
Dim intCurrentIndex As Integer = 0
-
Dim connectionString As String = "Data Source=MY-ANASTASIA;Initial Catalog=ISM;Integrated Security=True"
-
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT CertExamID, MemberName, ExamName, ExamDate, ExamNo FROM ExamCertificate", connectionString)
-
Dim connection As SqlConnection = New SqlConnection(connectionString)
-
da.Fill(ds)
-
connection.Open()
-
da.SelectCommand.Connection = connection
-
-
Try
-
Dim command As SqlCommand = New SqlCommand("InsertExam", connection)
-
command.CommandType = CommandType.StoredProcedure
-
-
command.Parameters.Add("@CertExamID", SqlDbType.VarChar, 40, Me.txtID.Text)
-
command.Parameters.Add("@MemberName", SqlDbType.VarChar, 40, Me.txtName.Text)
-
command.Parameters.Add("@ExamName", SqlDbType.VarChar, 40, Me.txtExam.Text)
-
command.Parameters.Add("@ExamDate", SqlDbType.VarChar, 40, Me.txtDateExam.Text)
-
command.Parameters.Add("@ExamNo", SqlDbType.VarChar, 40, Me.txtNo.Text)
-
-
Console.WriteLine("Rows inserted: " + _
-
command.ExecuteNonQuery().ToString)
-
Catch ex As Exception
-
Console.WriteLine(ex.Message)
-
Throw
-
Finally
-
connection.Close()
-
End Try
-
End Sub
-
-----------
-
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNext1.Click
-
Dim ds = New DataSet
-
Dim connectionString As String = "Integrated Security=SSPI;Persist Security Info=true; Initial Catalog=ISM;Data Source=MY-ANASTASIA"
-
Dim intCurrentIndex As Integer = 0
-
Dim connection As SqlConnection = New SqlConnection(connectionString)
-
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT CertExamID, MemberName, ExamName, ExamDate, ExamNo FROM ExamCertificate", connectionString)
-
-
connection.Open()
-
-
If intCurrentIndex > ds.Tables(0).Rows.Count - 1 Then
-
-
'Add one to the current index.
-
intCurrentIndex = intCurrentIndex + 1
-
-
txtID.Text = ds.Tables(0).Rows(intCurrentIndex).Item("CertExamID").ToString()
-
txtName.ValidationGroup = ds.Tables(0).Rows(intCurrentIndex).Item("MemberName").ToString()
-
txtExam.Text = ds.Tables(0).Rows(intCurrentIndex).Item("ExamName").ToString()
-
txtDateExam.ValidationGroup = ds.Tables(0).Rows(intCurrentIndex).Item("ExamDate").ToString()
-
txtNo.Text = ds.Tables(0).Rows(intCurrentIndex).Item("ExamNo").ToString()
-
End If
-
-
Try
-
Console.WriteLine(connection.State.ToString())
-
Finally
-
connection.Close()
-
End Try
-
End Sub
-
-------------
-
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
-
Dim ds = New DataSet
-
Dim connectionString As String = "Integrated Security=SSPI;Persist Security Info=true; Initial Catalog=ISM;Data Source=MY-ANASTASIA"
-
Dim intCurrentIndex As Integer = 0
-
Dim StrSQL = "insert into ExamCertificate(CertExamID,MemberName,ExamName,ExamDate,ExamNo) values(" & (txtID.Text.Trim) & "," & (txtName.Text.Trim) & "," & (txtExam.Text.Trim) & "," & (txtDateExam.Text.Trim) & "," & (txtNo.Text.Trim) & ")"
-
Dim connection As SqlConnection = New SqlConnection(connectionString)
-
-
connection.Open()
-
-
txtID.Text = ""
-
txtName.Text = ""
-
txtExam.Text = ""
-
txtDateExam.Text = ""
-
txtNo.Text = ""
-
-
Try
-
-
-
Dim command As SqlCommand = _
-
New SqlCommand("InsertExam", connection)
-
command.CommandType = CommandType.StoredProcedure
-
-
command.Parameters.AddWithValue("@CertExamID", txtID.Text)
-
command.Parameters.AddWithValue("@MemberName", txtName.Text)
-
command.Parameters.AddWithValue("@ExamName", txtExam.Text)
-
command.Parameters.AddWithValue("@ExamDate", txtDateExam.Text)
-
command.Parameters.AddWithValue("@ExamNo", txtNo.Text)
-
-
Catch ex As Exception
-
-
End Try
-
Try
-
Console.WriteLine(connection.State.ToString())
-
Finally
-
connection.Close()
-
End Try
-
End Sub
-
End Class
-
-------
Please give advice where it goes wrong because it keep saying parameter is not supplied and if i put parameter into my sp it wilI say i did not put any parameter. I also need an image steps to develop this web app.
TQ in advance
3 1993
Posting such huge chunk of code won't help.... post the part of the code that's problematic
Check if you're passing the first parameter of the stored procedure youre passing is not null or blank
Tq for ur advice thatGuy. when i click new data and save i'll get that error. Hope u can help me.. -
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave1.Click
-
Dim StrSQL = "insert into ExamCertificate(CertExamID,MemberName,ExamName,ExamDate,ExamNo) values(" & (txtID.Text.Trim) & "," & (txtName.Text.Trim) & "," & (txtExam.Text.Trim) & "," & (txtDateExam.Text) & "," & (txtNo.Text) & ")"
-
Dim ds As New DataSet
-
Dim intCurrentIndex As Integer = 0
-
Dim connectionString As String = "Data Source=MY-ANASTASIA;Initial Catalog=ISM;Integrated Security=True"
-
Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT CertExamID, MemberName, ExamName, ExamDate, ExamNo FROM ExamCertificate", connectionString)
-
Dim connection As SqlConnection = New SqlConnection(connectionString)
-
da.Fill(ds)
-
connection.Open()
-
da.SelectCommand.Connection = connection
-
-
Try
-
Dim command As SqlCommand = New SqlCommand("InsertExam", connection)
-
command.CommandType = CommandType.StoredProcedure
-
command.Parameters.Add("@CertExamID", SqlDbType.VarChar, 40, Me.txtID.Text)
-
command.Parameters.Add("@MemberName", SqlDbType.VarChar, 40, Me.txtName.Text)
-
command.Parameters.Add("@ExamName", SqlDbType.VarChar, 40, Me.txtExam.Text)
-
command.Parameters.Add("@ExamDate", SqlDbType.VarChar, 40, Me.txtDateExam.Text)
-
command.Parameters.Add("@ExamNo", SqlDbType.VarChar, 40, Me.txtNo.Text)
-
Console.WriteLine("Rows inserted: " + _
-
command.ExecuteNonQuery().ToString)
-
Catch ex As Exception
-
Console.WriteLine(ex.Message)
-
Throw
-
Finally – the problem shows here
-
connection.Close()
-
End Try
-
End Sub
-----
My stored proc - CREATE PROCEDURE [dbo].[InsertExam]
-
-
@CertExamID int,
-
@MemberName nvarchar(50),
-
@ExamName nvarchar(50),
-
@ExamDate datetime,
-
@ExamNo int
-
AS
-
BEGIN
-
SET NOCOUNT ON;
-
Select
-
CertExamID,
-
MemberName,
-
ExamName,
-
ExamDate,
-
ExamNo
-
from dbo.ExamCertificate
-
-
INSERT INTO ExamCertificate
-
( CertExamID,
-
MemberName,
-
ExamName,
-
ExamDate,
-
ExamNo )
-
VALUES
-
-
( @CertExamID,
-
@MemberName,
-
@ExamName,
-
@ExamDate,
-
@ExamNo )
-
End
TQ
Line 23 in your code you have: Console.WriteLine(ex.Message)
Why do you have Console.WriteLine in an ASP.NET application???
Anyways, you aren't supplying values you to your parameters properly.
Please review the following article that outline how to use a database: Database tutorial Part 1 Database tutorial Part 2[/quote]
In Part 1 there are examples on how to use parameters properly.
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Learn Dot.Net |
last post by:
I tried to open a new web application project in C# and I have an alert "The
operation could not be completed". The same project on VB.NET I open without
problem. What do I have to do. I use a disc...
|
by: CES |
last post by:
All,
If anyone has been following my trials over the last week see(Setting up a
Web Application on IIS 5.1 and ASP.Net Security Problems).
I'm having a problem running a Asp.Net Web...
|
by: Krzysztof Swiezynski |
last post by:
Hello,
I've made a simple web application which display a welcome string based
on the choosen language selected (values: "pl" or "en") from a
DropDownList. My code is:
protected ResourceManager...
|
by: JuneT |
last post by:
Has anyone encountered the error as follows:
"The page requires session state that is no longer available. Either the
session has expired, the client did not send a valid session cookie, or the...
|
by: bseakgano |
last post by:
I have developed a intranet . Using HTML , SQL and ASP . I have created a table with SQL is just fine . And design a form is just looks fine to me . But when I try to insert Data into the SQL I just...
|
by: kokimisev |
last post by:
I'm new on ASP.NET programming. I'm working with Visual Studio 2005. I have made this web application using C# language. I'm using prepared components like AccessDataSource. After creating I tested...
|
by: arial |
last post by:
Hi all I am getting this error message while try to insert data using my .net webform.
Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '1'.
Source Error:
...
|
by: vikas1111 |
last post by:
Hi All..
While putting data into database from form if i refresh the php form a blank data will be added into database ... How can i remove that bug???
Here is my code....
<?php...
|
by: AlexanderDeLarge |
last post by:
Hi!
I got a problem that's driving me crazy and I'm desperately in need of help.
I'll explain my scenario:
I'm doing a database driven site for a band, I got these tables for their discography...
|
by: vivekgs2007 |
last post by:
hi to all,
I am using the php from last 1 year…this is my first framework i am using i downloaded CodeIgniter and made the configaration as listed above..i am also using wamp server..
I am getting...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |