不使用文本框将数据插入表中 [英] Insert data into a table without using textboxes

查看:52
本文介绍了不使用文本框将数据插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,用户可以使用用户名和密码进行注册。我有一个有两个表的数据库。 Table1已包含用户配置文件。用户ID,姓名,年龄,地址,城市,州,电子邮件,级别。在表2中,它设置为具有UserID,电子邮件,密码,级别。我有一个代码,当用户在文本框中输入他们的电子邮件和密码并单击提交时,它会保存到Table2中,但它缺少UserId和Level。有没有办法可以将这两个字段放到Table2而不将其输入文本框?我被困在这一部分上了!



<前lang =c#> 受保护 void Submit_Click( object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ PasswordConnectionString]的ConnectionString);
con.Open();
string cmdStr = 选择INST_ID,accessLevel ,TableCEO中的EmailAddress插入TableSecurity,其中EmailAddress =' + TextBoxEA.Text + ';
string cmdStr2 = 选择INST_ID,accessLevel ,来自TableIALO的EmailAddress插入TableSecurity,其中EmailAddress =' + TextBoxEA.Text + ';
string insCmd = 插入TableSecurity( EmailAddress,Password)值(@EmailAddress,@ Password);
string insCmd2 = 插入TableSecurity( EmailAddress,Password)值(@EmailAddress,@ Password);
SqlCommand insertUser = new SqlCommand(insCmd,con);
SqlCommand insertUser2 = new SqlCommand(insCmd2,con);
insertUser.Parameters.AddWithValue( @ EmailAddress,TextBoxEA.Text);
insertUser.Parameters.AddWithValue( @ Password,TextBoxPW.Text);



}

}





好​​的这是我到目前为止所尝试的但它仍然无效。我已经用我改变的内容更新了代码。表2中保存的唯一内容是电子邮件和密码。如何将UserID和Level连同电子邮件和密码一起输入Table2?

解决方案

由于Harshi的答案是确切的,但可能我可以在此添加更多信息!!



首先通过电子邮件ID从table1中选择字段。

从table1中选择UserID,Level,其中emailid = txtemail.Text



然后


I have a form that a user can signup with a username and password. I have a database that has two tables. Table1 has the user profile already in it. UserID, Name, Age, Address, City, State, Email, Level. In Table2 it is setup to have UserID, Email, Password, Level. I have a code that when the user puts in their email and password in the textboxes and click submit it is saved into Table2 but it is missing the UserId and Level. Is there a way I can get these two fields to Table2 without entering it into a textboxes? I am stuck on this part!

protected void Submit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "Select INST_ID, accessLevel, EmailAddress from TableCEO insert into TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
        string cmdStr2 = "Select INST_ID, accessLevel, EmailAddress from TableIALO insert into TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
        string insCmd = "Insert into TableSecurity (EmailAddress, Password) values (@EmailAddress, @Password)";
        string insCmd2 = "Insert into TableSecurity (EmailAddress, Password) values (@EmailAddress, @Password)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        SqlCommand insertUser2 = new SqlCommand(insCmd2, con);
        insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        

        
    }
   
}



Ok This is what I have tried so far but it still does not work. I have updated the code with what I have changed. The only thing that is saved into Table2 is the Email and the password. How can I get the UserID and Level into Table2 along with the email and password?

解决方案

As Harshi answer is Exact but may be i can add some more info on this!!

first select fields from table1 by email id,.
select UserID,Level from table1 where emailid=txtemail.Text

Then


这篇关于不使用文本框将数据插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆