-4

ラベルに整数値を格納し、別のフォームに渡したい。しかし、値は渡されますが、渡されますsystem.data.dataset。以下は私のコードです。これで私を助けてください。

con.Open();
SqlCommand cmd1 = new SqlCommand("select balance from customer where namee='" + textBox1.Text + "'", con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
adapter.Fill(ds, "loki");
label4.Text = ds.ToString();
options frm = new options(label4.Text);
frm.Show();
con.Close(); 
4

3 に答える 3

2

label.Text で残高フィールドの値を渡す必要があります。

これの代わりに

label4.Text = ds.ToString();

あなたはこのようにしました

label4.Text = ds.Tables[0].Rows["balance"].ToString();

ラベルの Text プロパティに文字列として格納されるため、別のフォームで取得する場合は、Int32.TryParseを使用して int に変換する必要があります。

于 2012-07-26T08:08:16.500 に答える
1

データセットの代わりに「スカラー」値を取得したい。

con.Open();
SqlCommand cmd1 = new SqlCommand("select balance from customer where namee='" 
                        + textBox1.Text + "'", con);
object balance = cmd.ExecuteScalar();
label4.Text = balance.ToString();

options frm = new options(label4.Text);
frm.Show();
con.Close(); 
于 2012-07-26T08:08:08.357 に答える
0

で試してください

con.Open();
SqlCommand cmd1 = new SqlCommand("select balance from customer where namee='" 
                        + textBox1.Text + "'", con);
label4.Text = cmd1.ExecuteScalar();
于 2012-07-26T08:10:54.940 に答える