【发布时间】:2014-10-10 22:14:19
【问题描述】:
我想在 mysql 数据库中将单选按钮值存储为男性和女性,因此我使用 c# 使用 windows 商店应用程序
这是我的 C# 代码
private void addButton_Click(object sender, RoutedEventArgs e)
{
try
{
string Query = @"INSERT INTO `bcasdb`.`tbl_student`
(`reg_id`,
`std_fname`,
`std_lname`,
`tbl_batch_batch_id`,
`gender`)
VALUES (@regId, @fName, @lName, @bID, @gender)";
//This is command class which will handle the query and connection object.
MySqlConnection conn = new MySqlConnection(BCASApp.DataModel.DB_CON.connection);
MySqlCommand cmd = new MySqlCommand(Query, conn);
conn.Open();
cmd.Parameters.AddWithValue("@regId", this.regIDInput.Text);
cmd.Parameters.AddWithValue("@fName", this.fnameInput.Text);
cmd.Parameters.AddWithValue("@lName", this.lnameInput.Text);
cmd.Parameters.AddWithValue("@bID", this.batchIDInput.Text);
//cmd.Parameters.AddWithValue("@gender", );
cmd.ExecuteNonQuery();
conn.Close();
successmsgBox();
}
catch (Exception)
{
errormsgBox();
}
}
private void genderInput_Checked(object sender, RoutedEventArgs e)
{
}
这是我的 xaml 编码
<StackPanel Orientation="Horizontal" Margin="20,20,0,10">
<RadioButton Name="maleInput" Content="Male" Checked="genderInput_Checked" Width="75"></RadioButton>
<RadioButton Name="femaleInput" Content="Female" Checked="genderInput_Checked" Width="162"></RadioButton>
</StackPanel>
【问题讨论】:
标签: c# mysql xaml windows-store-apps radio-button