ExecuteReader; Commandtext property has not been initialized.Can anyone help me?Plaease.Here is my code.

Nyan Lynn Phyoe 1 Reputation point
2021-12-08T05:27:49.413+00:00

using System.Windows.Forms;
using ESportCenter.DBA;

namespace ESportCenter.MasterData
{
public partial class frm_regi : Form
{
public frm_regi()
{
InitializeComponent();
}

    clsRegi obj_clsRegi = new clsRegi();
    clsMainDB obj_clsMainDB = new clsMainDB();

    DataTable DT = new DataTable();
    public bool _IsEdit = false;
    public int _PlayerID = 0;
    string SPString = "";


    private void frm_regi_Load(object sender, EventArgs e)
    {
        string Day = string.Format("{0:D2}", DateTime.Now.Day);
        string Month = string.Format("{0:D2}", DateTime.Now.Month);
        string Year = string.Format("{0:D2}", DateTime.Now.Year);
        lblStartDate.Text = Month + "/" + Day + "/" + Year;
        txtMemberFees.Text = "0";
        txtPlayerName.Focus();
    }

    private void btnClose_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        int OK;
        if (txtPlayerName.Text.Trim().ToString() == string.Empty)
        {
            MessageBox.Show("Please Type PlayerName");
            txtPlayerName.Focus();
        }
        else if (txtPassword.Text.Trim().ToString() == string.Empty)
        {
            MessageBox.Show("Please Type Password");
            txtPassword.Focus();
        }
        else if (txtMemberFees.Text.Trim().ToString() == string.Empty)
        {
            MessageBox.Show("You need money to play");
            txtMemberFees.Focus();
        }
        else if (int.TryParse(txtMemberFees.Text, out OK) == false)
        {
            MessageBox.Show("Cash Should Be Number");
            txtMemberFees.Focus();
        }
        else if (Convert.ToInt32(txtMemberFees.Text) < 3000 || Convert.ToInt32(txtMemberFees.Text) > 10000000)
        {
            MessageBox.Show("Cash Amount Should be between 3000 and 10 Laks ");
            txtMemberFees.Focus();
            txtMemberFees.SelectAll();
        }
        else
        {
            SPString = string.Format("SP_Select_Regi N'{0}',N'{1}',N'{2}'", txtPlayerName.Text.Trim().ToString(), "0", "0");

        }
        DT = obj_clsMainDB.SelectData(SPString);
        if (DT.Rows.Count > 0 && _PlayerID != Convert.ToInt32(DT.Rows[0]["PlayerID"]))
        {
            MessageBox.Show("This Player Is Already Exit");
            txtPlayerName.Focus();
            txtPlayerName.SelectAll();
        }
        else
        {
            obj_clsRegi.PLAYERID = _PlayerID;
            obj_clsRegi.PLAYERNAME = txtPlayerName.Text;
            obj_clsRegi.PASSWORD = txtPassword.Text;
            obj_clsRegi.MEMBERFEES = Convert.ToInt32(txtMemberFees.Text);
            obj_clsRegi.STARTDATE = lblStartDate.Text;
            if (_IsEdit)
            {
                obj_clsRegi.ACTION = 1;
                obj_clsRegi.SaveData();
                MessageBox.Show("Successfully Edit", "Successfully", MessageBoxButtons.OK);
                this.Close();
            }
            else
            {
                obj_clsRegi.ACTION = 0;
                obj_clsRegi.SaveData();
                MessageBox.Show("Successfully Save", "Successfully", MessageBoxButtons.OK);
                this.Close();
            }

        }
    }
}

}

Azure SQL Database
SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. YufeiShao-msft 7,146 Reputation points
    2021-12-08T06:34:36.83+00:00

    Hi @

    from this case
    The adapter needs to pass the command text to the command object, you lack the SelectCommand in your adapter probably.

    You should set the CommandText property of the command object with your SELECT statement or stored procedure name, you cannot execute an empty command.

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. WhTurner 1,611 Reputation points
    2021-12-08T12:19:08.427+00:00

    As this is not about the Small Basic language, please remove the "small-basic" tag.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.