在c#中的另一个文本框中插入数据时自动填充文本框的代码

时间:2016-03-04 07:44:09

标签: c#

我想在插入会员ID时自动填充/填写会员名称 我在成员ID的文本更改事件上处理以下代码 -

try
        {

            //int RowsAffected = 0;
            DataAccess oDataAccess = new DataAccess();
            con.Open();
            oDataAccess.cmd.CommandText = "SELECT MemberName FROM AccountInfo where MemberID='" + tbMemberID.Text + "'";
            oDataAccess.cmd.Connection = con;

            tbMemberName.Text = ((string)cmd.ExecuteScalar());
//@this line it shows error - object reference not set to an instance of object
            con.Close();
        }

        catch (Exception ex)
        {

            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

0 个答案:

没有答案