我正在尝试使用类中的按钮单击设置公共 int,然后使用创建新实例并使用另一个类中的值然后将其插入数据库。
我正在使用 webforms 和 C# 来生成我的系统。对此的任何帮助都非常感谢。
1 级--------------------------------
public partial class Index : System.Web.UI.Page
{
public int ID1;
public void bLogin_Click(object sender, EventArgs e)
{
string username = tbUsername.Text;
string password = tbPassword.Text;
SqlCommand cmd2 = new SqlCommand("select UsersID from [dbo].[Users] where Username=@uname and Password=@password");
cmd2.Connection = con;
cmd2.Parameters.AddWithValue("@uname", tbUsername.Text);
cmd2.Parameters.AddWithValue("@password", tbPassword.Text);
int Result2 = (int)cmd2.ExecuteScalar();
ID1 = Result2;
if (Result > 0)
{
MessageBox.Show("Welcome");
MessageBox.Show(ID1.ToString());
Response.Redirect("Dashboard.aspx");
con.Close();
}
else
{
MessageBox.Show("Incorrect");
}
}
}
}
第 2 类 -----------------------------------
protected void bSubmit_Click(object sender, EventArgs e)
{
SQLDatabase.DatabaseTable module_table = new SQLDatabase.DatabaseTable("Boards"); // Need to load the table we're going to insert into.
SQLDatabase.DatabaseRow new_row = module_table.NewRow(); // Create a new based on the format of the rows in this table.
Index index = new Index();
string new_id = module_table.GetNextIDBoards().ToString(); // Use this to create a new ID number for this module. This new ID follows on from the last row's ID number.
string title = tbTitle.Text;
string body = tbContent.Text;
DateTime now = DateTime.Now;
string date = now.GetDateTimeFormats('d')[0];
string time = now.GetDateTimeFormats('t')[0];
}
您可以看到我正在尝试跨班级转移 ID。
数据库插入很好,但它的 ID 插入了“0”。
杨__羊羊
qq_笑_17
蓝山帝景
相关分类