Hi,
I am designing a web form and one of its pages is divided into two parts. The first section is stored in the data base and returns to me a number that I store in a session to use later by adding new data to the same record..and when writing the code and executing the program, the following message appears:
(System.ArgumentException: 'No mapping exists from object type System.Web.UI.WebControls.ListItem to a known managed provider native type.'
)
protected void AddVisitor_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(connoctionString))
{
using (SqlCommand command = new SqlCommand("AddVisitor", connection))
{
command.CommandType = CommandType.StoredProcedure;
connection.Open();
//command.Parameters["@VisitID"].Direction = ParameterDirection.Output;
command.Parameters.AddWithValue("@VisitID", (string)Session["VisitID"]);
command.Parameters.AddWithValue("@Visitor_name", VisitorName.Text);
command.Parameters.AddWithValue("@Nationality_ID", NationalDD.SelectedItem);
command.Parameters.AddWithValue("@org_id", Org.SelectedValue);
command.ExecuteNonQuery();
connection.Close();
can any one help me?
Jignesh KumarPosted Jan 18, 2023, 12:34 PM
You need to change just line with "@VisitID" to "@Visit_ID"
and your filnal code should look like,
Naimish MakwanaPosted Jan 18, 2023, 11:38 AM
Hello Name,
Your procedure parameter is @Visit_ID and you are passing @VisitID. So change
To
Thanks
Naimish Makwana
Name MamePosted Jan 18, 2023, 11:21 AM
Many thanks for your help ...
it's work :) ...
Now , in 2nd part ,i wrote this code which i bring the session Visit_ID to this part
using (SqlCommand command1 = new SqlCommand("strtVisit", con))
{
command1.CommandType = CommandType.StoredProcedure;
con.Open();
command1.Parameters.AddWithValue("@VisitID", Convert.ToInt32(Session["VisitID"]));
command1.Parameters.AddWithValue("@Visitor_name", VisitorName.Text);
command1.Parameters.AddWithValue("@Nationality_ID", NationalDD.SelectedIndex);
command1.Parameters.AddWithValue("@org_id", Org.SelectedItem.Value);
command1.ExecuteNonQuery();
con.Close();
}
and the message is appear
{Procedure or function StrtVisit expects parameter @Visit_ID, which was not supplied.} System.Exception {System.Data.SqlClient.SqlException}
and the save not complete :(
Note: " i need procedure which save a list of names and their details and then store it in the database after it split "
Rijwan AnsariPosted Jan 18, 2023, 11:10 AM
Hi,
Can you please share your code using session or session conversion to list?
Sachin SinghPosted Jan 18, 2023, 10:58 AM
use below parameters
Make sure, VisitID, Nationality_ID and Org_Id are if int type in your table, Otherwise type cast accordingly.
Naimish MakwanaPosted Jan 18, 2023, 9:15 AM
Hello Name,
The problem may be
Try one of the below.
Thanks.
Jignesh KumarPosted Jan 18, 2023, 9:04 AM
change your session to Convert.ToInt() then it should work
Name MamePosted Jan 18, 2023, 8:48 AM
Thanks sir
when running the code after the changing , it give me this error
(System.Data.SqlClient.SqlException: 'Error converting data type nvarchar to int.'
) for the (command.ExecuteNonQuery();)
Jignesh KumarPosted Jan 18, 2023, 8:22 AM
Hello,
You are passing dropdown.SelectedItem, you should pass selectedItem.Value