Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void GetSubjectDetails(int id)
        {
            var conn = new SqlConnection(Connectionstring);
            conn.Open();

            var command = new SqlCommand("SELECT [sub_id],[sub_name],[lev_id],[hours],[status] FROM [DB_SchoolManager].[dbo].[tbl_subjects] where [sub_id]=@sub_id", conn);
            command.Parameters.AddWithValue("@sub_id", id);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                if (reader.Read())
                {
                    TxtSubject.Text = reader["sub_name"].ToString();
                    TxtHours.Text = reader["hours"].ToString();
                    CbLevels.SelectedValue = int.Parse(reader["lev_id"].ToString());
                    if (reader["status"].ToString()=="Blocked")
                    {
                        CbStatus.SelectedIndex = 1;
                    }
                    else
                    {
                        MessageBox.Show(reader["status"].ToString().Length.ToString());
                        CbStatus.SelectedIndex = 0;
                    }
                    
                }
            }
            conn.Close();
        }


CREATE TABLE [dbo].[tbl_subjects](
	[sub_id] [int] IDENTITY(1,1) NOT NULL,
	[sub_name] [nchar](200) NOT NULL,
	[lev_id] [nchar](200) NOT NULL,
	[hours] [nchar](200) NOT NULL,
	[status] [nchar](200) NOT NULL,
 CONSTRAINT [PK_tbl_subjects] PRIMARY KEY CLUSTERED 
(
	[sub_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO


What I have tried:

should i change
[nchar](200)

but i need to save in Arabic which unrecognized for it
Posted
Updated 5-Jan-19 9:55am

1 solution

nchar is fixed size: say nchar(200) and that is exactly what you get - no more, no less.
If you want "up to 200", then use nvarchar(200)
 
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