是否可以将一个文本框值发送到2个数据库中? [英] Is it possible to send one text box value into 2 databases?

查看:47
本文介绍了是否可以将一个文本框值发送到2个数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......我在文件后面创建了一个aspx页面和代码。在我的aspx页面中,我创建了一些用于输入用户详细信息的文本框,我试图将这些文本框详细信息存储到2个数据库中......但是该文本框详细信息仅存储在一个数据库表中...在其他数据库中,它只插入一个空值...这是我的代码...



/ /txtfname,txtlname....all是我的文本框Id's ....我在这段代码中犯了错误?请建议我...提前感谢....



Hi...I create one aspx page and code behind file..In my aspx page i create some text boxes for enter user details,and i am trying to store those text box details into 2 data bases...But that text box details stored into one database table only...In other database it inserted with only one empty value...This is my code...

//txtfname,txtlname....all are my text box Id's....Where i did a mistake in this code??please suggest me...thanks in advance....

strSqlCommand = "insert into cntus values('" + txtfname.Text + "','" + txtlname.Text + "','" + txtdesignation.Text + "','" + txtmail.Text + "','" + txtmobile.Text + "')";
            cmd = new SqlCommand(strSqlCommand, con);
            if (cmd.ExecuteNonQuery() > 0)
            {
                lblsuccess.Text = "<b style="color:green">Details submitted Succesfully</b>";
                SendMail();
                txtfname.Text = string.Empty;
                txtlname.Text = string.Empty;
                txtdesignation.Text = string.Empty;
                txtmail.Text = string.Empty;
                txtmobile.Text = string.Empty;
            }
            else
            {
                lblsuccess.Text = "<b style="color:red">Details not submitted</b>";
            }
            con.Close();
            BindData();
        }
        if (con.State != ConnectionState.Open)
        {
            con.Open();
        }
         //string name = txtfname.Text;
        strSqlCommandPass = "insert into password values('" +txtfname.Text+"','" + txtlname.Text + "')";
        cmd = new SqlCommand(strSqlCommandPass,con);
        cmd.ExecuteNonQuery();
    }

推荐答案

是的。



但请不要不要使用字符串连接来形成SQL语句! 特别具有用户提供的值。每次都使用参数化语句。



但是,在上面的代码中,看起来你在尝试将它们保存到第二个表之前清空TextBox值。 />


Yes.

But PLEASE don't use string concatenation to form SQL statements! Particularly with values provided by the user. Use parameterized statements every time.

However, in the code above, it looks like you empty out the TextBox values before trying to save them to the second table.

txtfname.Text = string.Empty;
txtlname.Text = string.Empty;


这篇关于是否可以将一个文本框值发送到2个数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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