I work in windows form c# vs 2015 i get error i need to solve it
but i dont know how to solve it
i write function in textbox changed event but when i start writing in textbox
get error object reference not set to an instance of object .
so that why this problem happen and how to solve it .
in textbox changed event
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- try
- {
-
-
- MatrixClass matrix = new MatrixClass();
- string value1 = matrix.GetAtcCode(textBox3.Text);
- textBox1.Text = value1;
-
-
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- public string GetAtcCode(string GenericName)
- {
- SqlConnection con = new SqlConnection(connection);
-
- con.Open();
-
- SqlCommand comm = new SqlCommand("ATC_Code_ByGeneric_H", con);
-
- comm.CommandType = CommandType.StoredProcedure;
-
- comm.Parameters.Add(new SqlParameter("@Lvl_Name", GenericName));
-
- string ret = comm.ExecuteScalar().ToString();
- con.Close();
-
- return ret;
-
- }
stored procedure
- ALTER PROCEDURE [dbo].[ATC_Code_ByGeneric_H]
- @Lvl_Name nvarchar(500)
- AS
- SELECT Tbl_Lvl1.Code + Tbl_Lvl2.Code + Tbl_Lvl3.Code + Tbl_Lvl4.Code + Tbl_Lvl5.Code AS ATC_Code
- FROM Tbl_Lvl1
- INNER JOIN
- Tbl_Lvl2
- ON Tbl_Lvl1.S_ID = Tbl_Lvl2.UpLvl_ID
- INNER JOIN
- Tbl_Lvl3
- ON Tbl_Lvl2.S_ID = Tbl_Lvl3.UpLvl_ID
- INNER JOIN
- Tbl_Lvl4
- ON Tbl_Lvl3.S_ID = Tbl_Lvl4.UpLvl_ID
- INNER JOIN
- Tbl_Lvl5
- ON Tbl_Lvl4.S_ID = Tbl_Lvl5.UpLvl_ID
- WHERE (Tbl_Lvl5.Lvl_Name = @Lvl_Name) and Tbl_Lvl5.human=1
- RETURN