Your problem is that textboxes and labels do not have a DataSource. However you can assign values to their .Text property (like the link from @FeroseKhan)
@FARONO has also noted that you are vulnerable to SQL Injection. You should never build queries by concatenating strings of user input. Use Parameters instead.
For example in your case it would be something like this:
private void input_btn_Click(object sender, EventArgs e)
{
var connectString = Properties.Settings.Default.SandboxConnectionString;
SqlConnection conn = new SqlConnection(connectString);
DataTable dt = new DataTable();
string query = "Select Id, name from player_tbl where Id=@id";
SqlDataAdapter SDA = new SqlDataAdapter(query, conn);
var parameter = SDA.SelectCommand.Parameters.AddWithValue("@id", num_input.Text);
SDA.Fill(dt);
if (dt.Rows.Count > 0)
{
win_num.Text = dt.Rows[0]["Id"].ToString();
win_name.Text = dt.Rows[0]["name"].ToString();
}
else
{
win_num.Text = "";
win_name.Text = "No Result";
}
}
Note the differences in the query - I'm getting both values in the same select. I haven't used "Select * from player_tbl" because I want to be in control of what is returned and in what order the columns are presented.
I've also replaced
where Id='" + int.Parse(num_input.text)
with
where Id=@id
- If
Id
is a string (hint, it probably shouldn't be) then I don't have to worry about the single quotes. Nor do I have to worry about converting the textbox text to an integer first - the parameter handles all of that for me.
An even better solution would be to wrap the connection and dataadaptor with a
using
block e.g.
using (var conn = new SqlConnection(connectString))
{
string query = "Select id, name from player_tbl where Id=@id";
DataTable dt = new DataTable();
using (var SDA = new SqlDataAdapter(query, conn))
{
var parameter = SDA.SelectCommand.Parameters.AddWithValue("@id", num_input.Text);
SDA.Fill(dt);
}
if (dt.Rows.Count > 0)
{
win_num.Text = dt.Rows[0]["id"].ToString();
win_name.Text = dt.Rows[0]["name"].ToString();
}
else
{
win_num.Text = "";
win_name.Text = "No Result";
}
}