Hi Guys,
I am trying to insert hashtable in databse but one of the key in hashtable is null.Can anyone help me write an exception for this.Or if i can just move to the next key .

Thanks a lot

private void btnUrdu_Click(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection(@"Server=208.124.179.197;Database=RTLUser;UID=sa;");
            DataSet CustomersDataSet = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
            SqlCommandBuilder cmdBuilder;
            string myString;
            DataSet ds = new DataSet();
            //cn.ConnectionString = "Server=server;Database=RTLUser;UID=sa;";
            cn.Open();
            SimpleUrduDict.SimpleUrduDictionary ins = new SimpleUrduDictionary();

            Hashtable aaa = ins.AllWords();
            StringBuilder insertCommand = new StringBuilder();
            IDictionaryEnumerator en = aaa.GetEnumerator();
            if (aaa.Count > 0)
            {

                while (en.MoveNext())
                {

                    string al = en.Value.ToString();
                    string al2 = en.Key.ToString();
                    string al3 = "";
                    string al4 = "";
                    al3 = al.Replace("'", "''");
                    al4 = al2.Replace("'", "''");
                    myString = @"INSERT INTO TblUrdu (word,definition) Values('" + al4 + "','" + al3 + "')";
                    SqlCommand myCmd = new SqlCommand(myString, cn);
                    myCmd.ExecuteNonQuery();
                }
                

            }


            cn.Close();
var al = en.Value == null ? String.Empty : en.Value.ToString();
...
if(!String.IsNullOrEmpty(al)) { // Do your stuff }
...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.