Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear friends, do not bother
I do not know what the problem with this code is that all this was the error
I can not fix it
Code is:
Page was loaded in the filling comboBox

C#
private void view_list_User_DDL()
        {
            try
            {
                //نمایش جدول کاربران
                if (scon.State == ConnectionState.Closed)
                    scon.Open();
                SqlDataAdapter sda = new SqlDataAdapter("Select_User_DDL", scon);
                sda.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                sda.Fill(dt);
                comboBox2.DataSource = dt;
                comboBox2.DisplayMember = "l_name";
                comboBox2.ValueMember = "id_user";
            }
            catch (Exception err)
            {
                MessageBox.Show("ERROR" + err, "اخطار", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                scon.Close();
            }
        }

And here is the next code
:
C#
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //نمایش نام کاربر
                if (scon.State == ConnectionState.Closed)
                    scon.Open();
                SqlCommand scm = new SqlCommand("Select_Lname_Fname", scon);
                scm.CommandType = CommandType.StoredProcedure;
                scm.Parameters.AddWithValue("@id_user", comboBox2.SelectedValue);
                SqlDataReader sdr = scm.ExecuteReader();
                if (sdr.HasRows)
                {
                    sdr.Read();
                    label10.Text = sdr[0].ToString();
                    sdr.Close();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("ERROR" + err, "اخطار", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                scon.Close();
            }
        }



Here is a program error
Khvahsha friends help me
Thank you

ERRORSystem.ArgumentException: No mapping exists from object type System.Data.DataRowView to a known managed provider native type.
   at System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen, Boolean streamAllowed)
   at System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
   at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
   at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
   at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader()
   at ShafieiNan.Sel.comboBox2_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\PCTirTash\documents\visual studio 2010\Projects\ShafieiNan\ShafieiNan\Sel.cs:line 292
Posted

This error is raised because, while you loading data to combobox, the selectedIndexChanged event calls. ie from here in your code.
C#
comboBox2.DisplayMember = "l_name";
                comboBox2.ValueMember = "id_user";

at this time the selectedValue will be set to datarow.
and this is the reason why error is coming.

Please check
 
Share this answer
 
Friends my problem was resolved

Reference[^]
 
Share this answer
 
Hey thanks for your answer
I first read data from the database and displayed in comboBox2
And then select any option other information displayed comboBox2
What should I do
 
Share this answer
 
Comments
Nelek 25-Nov-14 3:43am    
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional message.
So I need this code
Help me please
 
Share this answer
 
Comments
Nelek 25-Nov-14 3:43am    
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional message.
The problem was solved

Reference[^]
 
Share this answer
 

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



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