C# 如何:将结果添加到与登录相同的数据库
我的应用程序显示了一家餐厅的菜单,在使用数据库中的电子邮件和密码登录后,客户端会引导您进入一台计算机,该计算机会在特定日期后计算Kcal。我希望能够把结果放在客户机用作图像的相同数据库和数据中。 [ 这是我参加比赛的申请表C# 如何:将结果添加到与登录相同的数据库,c#,sql,asp.net,C#,Sql,Asp.net,我的应用程序显示了一家餐厅的菜单,在使用数据库中的电子邮件和密码登录后,客户端会引导您进入一台计算机,该计算机会在特定日期后计算Kcal。我希望能够把结果放在客户机用作图像的相同数据库和数据中。 [ 这是我参加比赛的申请表 private void button1_Click(object sender, EventArgs e) { ani = Convert.ToInt32(textBox1.Text); cm = Convert.ToInt32(textBox2.Text)
private void button1_Click(object sender, EventArgs e)
{
ani = Convert.ToInt32(textBox1.Text);
cm = Convert.ToInt32(textBox2.Text);
kg = Convert.ToInt32(textBox3.Text);
s = ani + cm + kg;
if (s < 250) label_mesaj.Text = "1800";
else if (s >= 250 && s <= 275) label_mesaj.Text = "2200";
else label_mesaj.Text = "2500";
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("insert into Clienti(parola,nume,prenume,adresa,email)values('" + textBox4.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox6.Text + "')", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
}
private void按钮1\u单击(对象发送者,事件参数e)
{
ani=转换为32(textBox1.Text);
cm=转换为32(textBox2.Text);
kg=转换为32(textBox3.Text);
s=ani+cm+kg;
如果(s<250)标签_mesaj.Text=“1800”;
否则,如果(s>=250&&s,我就是这样设法解决这个问题的
我记得电子邮件的登录部分
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter("Select count(*) from Clienti where email='" + textBox1.Text + "' and Parola='" + textBox2.Text + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
client.email = textBox1.Text;
this.Hide();
Form4 ssss = new Form4();
ssss.Show();
}
else MessageBox.Show("verifica datele");
}
在下一种形式中
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter();
con.Open();if (s < 250) label_mesaj.Text = "1800";
da.UpdateCommand = new SqlCommand("Update Clienti set kcal_zilnice= '" + label_mesaj.Text + "' where email= '" + Form3.client.email.ToString() + "'", con);
da.UpdateCommand.ExecuteNonQuery();
da.UpdateCommand.Dispose();
con.Close();
}
private void按钮1\u单击(对象发送者,事件参数e)
{
SqlConnection con=新的SqlConnection(cont);
SqlDataAdapter da=新的SqlDataAdapter();
con.Open();如果(s<250)标签_mesaj.Text=“1800”;
da.UpdateCommand=new SqlCommand(“Update Clienti set kcal_zilnice=”+“label_mesaj.Text+”,其中email=”+“Form3.client.email.ToString()+”,con);
da.UpdateCommand.ExecuteOnQuery();
da.UpdateCommand.Dispose();
con.Close();
}
我就是这样设法解决这个问题的
我记得电子邮件的登录部分
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter("Select count(*) from Clienti where email='" + textBox1.Text + "' and Parola='" + textBox2.Text + "'", con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
client.email = textBox1.Text;
this.Hide();
Form4 ssss = new Form4();
ssss.Show();
}
else MessageBox.Show("verifica datele");
}
在下一种形式中
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter();
con.Open();if (s < 250) label_mesaj.Text = "1800";
da.UpdateCommand = new SqlCommand("Update Clienti set kcal_zilnice= '" + label_mesaj.Text + "' where email= '" + Form3.client.email.ToString() + "'", con);
da.UpdateCommand.ExecuteNonQuery();
da.UpdateCommand.Dispose();
con.Close();
}
private void按钮1\u单击(对象发送者,事件参数e)
{
SqlConnection con=新的SqlConnection(cont);
SqlDataAdapter da=新的SqlDataAdapter();
con.Open();如果(s<250)标签_mesaj.Text=“1800”;
da.UpdateCommand=new SqlCommand(“Update Clienti set kcal_zilnice=”+“label_mesaj.Text+”,其中email=”+“Form3.client.email.ToString()+”,con);
da.UpdateCommand.ExecuteOnQuery();
da.UpdateCommand.Dispose();
con.Close();
}
你可以把你的代码插入到Azure数据库中吗?A将会很棒。也要小心<代码> CON.OPEN()/代码>。我没有看到相应的<代码> CON.CONCEL()/代码>。你可能想考虑使用<代码>(SqLink Con=NealSqLink(CUCR)){}
相反,这将为您关闭并处理连接。这与con.close()无关,因为我想在登录时、登录并计算“kcal”后记住一个id我想将该答案添加到数据库中的该id。只需将该客户的id传入第二个表单的构造函数,或者您可以尝试在类中实现一个singleton模式,该模式将在“登录”期间保存所有客户详细信息 session@Sweet您的代码容易受到SQL注入攻击-您不应该将SQL语句构建为字符串,而应该使用命名参数,以便正确转义值。您不应该从用户输入构建SQL语句。您可以添加插入Azure数据库的代码吗?A将非常好。同时,请注意<代码> >打开()>代码>。我没有看到相应的<代码> CON.CONCELL()/代码>。您可能需要考虑使用“代码>使用(SQL连接CON=新SqLink(SCORC)){…} /代码>,因为这将关闭和处理连接。它不涉及CON.CUTIONE(),因为我想在登录后记住一个ID,在登录和计算之后。“kcal”我想将该答案添加到数据库中的该id中。只需将该客户的id传递给第二个表单的构造函数,或者您可以尝试在一个类中实现一个单例模式,该类将在“登录”过程中保存所有客户详细信息" session@Sweet您的代码容易受到SQL注入攻击-您不应该将SQL语句构建为字符串,而应该使用命名参数以便正确转义值。您永远不应该从用户输入构建SQL语句。