Hi,
im new to c#.When i execute the following code i get "vshost.exe has stopped working"
message. Firstly i insert some data to a table in sql server 2008.then i want to retrieve the MAX(Mem_ID). My insertion is working properly. But when im trying to retrive MAX(Mem_ID). It gives above error.
Plzz.. help me to make it work?

public String getLastMemID()
        {
            String ID = null;
            try
            {


                CN = new SqlConnection(concString);
                CN.Open();
            
                SqlCommand com = new SqlCommand("SELECT MAX(Mem_ID) FROM MemberMaster", CN);
                SqlDataReader dr = com.ExecuteReader();



                while (dr.Read())
                {


                    ID = dr.GetInt32(0).ToString();
                }


            }
            catch (SqlException ex)
            {
                MessageBox.Show("A SqlException. You must check the Querry parameteres");
                MessageBox.Show(ex.ToString());

            }
            finally
            {
                CN.Close();


            }
         
            return ID;
        }

Recommended Answers

All 2 Replies

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.