
SQL
USE [EmployeeDB]
GO
/****** Object: StoredProcedure [dbo].[spFetchWorkerDetails] Script Date: 6/25/2022 11:06:02 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spFetchWorkerDetails]@WorkerID int
AS
BEGINSET NOCOUNT ON;select *from Memberwhere WorkerID =@WorkerIDEND
SQL
USE [EmployeeDB]
GO
/****** Object: StoredProcedure [dbo].[SpGetWorkerNameList] Script Date: 6/25/2022 11:26:06 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SpGetWorkerNameList]
AS
BEGINSET NOCOUNT ON;
select -1 AS WorkerID, 'Select WorkName' as FirstName union
Select WorkerID,FirstName From Member ORDER BY WorkerID DESC , FirstName ;
ENDthis Query Get Name List
C#
private void DllName_SelectedIndexChanged(object sender, EventArgs e)
{
string EmpID = "";
SqlConnection connection = new SqlConnection(myconn);
SqlCommand cmd = new SqlCommand("spFetchWorkerDetails", connection);
cmd.Parameters.AddWithValue("@WorkerID", EmpID);
connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
SqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{
//txtboxID.Text = (dataReader["WorkerID"].ToString());
txtName.Text = (dataReader["FirstName"].ToString());
ComboxDesignation.Text = (dataReader["Designation"].ToString());
txtOccupation.Text = (dataReader["Occupation"].ToString());
txtCnic.Text = (dataReader["Cnic"].ToString());
txtWorkWith.Text = (dataReader["WorkWith"].ToString());
}
connection.Close();
}


Sachin SinghRank #66 · 26.2K reputationPosted Jun 26, 2022, 5:11 AM EDT
Please share the code where you have set Combobox items.
As it is a conversion error this means you have not set the value property of Combobox correctly.
A Combobox is set correctly as
comboBox.DisplayMember = "Text"; comboBox.ValueMember = "WorkerId"; var items = new[] { new { Text = "A", WorkerId= "1" }, new { Text = "B", WorkerId= "2" }, new { Text = "C", WorkerId= "3" }, new { Text = "D", WorkerId= "4" }, new { Text = "E", WorkerId= "5" } }; comboBox.DataSource = items;Guest UserRank #1,881 · 787 reputationPosted Jun 26, 2022, 1:57 PM EDT