本文介绍了将数据插入数据库两次,其他数据库中没有数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,当单击提交按钮时,它会获取数据并将其插入三个数据库。当用户单击提交按钮时,在两个表中有两个插入,每个表应该有一个插入。最后一张表根本没有得到任何数据。我做错了什么?



受保护 void ButtonSubmit_Click( object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ HotConnectionString ] .ConnectionString);
con.Open();

SqlCommand cmd = new SqlCommand( 插入表22(USERID,TOTAL_REVE,DATE,FINYR,INSTRUCTIO,RESEARCH,PUBLIC_SER,ACADEMIC_S,STUDENT_SE,INSTITUTIO,PHYSICAL_P,NET_AID,AUXILIARY_,HOSPITALS,INDEPENDEN,OTHEREXP,TOTASSETS,TOTLIABILITY,NoNEXPPERMRESASSETS,EXPENDABLE,UNRNETASSETS,TOTALREV ,TUITFEES,CURRDEBT,LONGTERMDEBT,TOTALNETASSETS)值(@USID,@ TOTAL_REVE,@ DATE,@ FINYR,@ INSTRUCTIO,@ RESEARCH,@ Public_SER,@ ACADEMIC_S,@ STUDENT_SE,@ INSTITUTIO,@ PHYSICAL_P,@ NET_AID,@ AUXILIARY_, @HOSPITALS,@ INDEPENDEN,@OTHEREXP,@ TOTASSETS,@ TOTLIABILITY,@ NoNEXPPERMRESASSETS,@ EXPENDABLE,@ UNRNETASSETS,@ TOTALREV,@ TOTITES,@ CURRDEBT,@ LongterMDEBT,@ TOTALNETASSETS)插入表23(USERID,TOTAL_REVE,DATE,FINYR ,INSTRUCTIO,RESEARCH,PUBLIC_SER,ACADEMIC_S,STUDENT_SE,INSTITUTIO,PHYSICAL_P,NET_AID,AUXILIARY_,HOSPITALS,INDEPENDEN,OTHEREXP,TOTASSETS ,TOTLIABILITY,NoNEXPPERMRESASSETS,EXPENDABLE,UNRNETASSETS,TOTALREV,TITITFEES,CURRDEBT,LONGTERMDEBT,TOTALNETASSETS)值(@USID,@ TOTAL_REVE,@ DATE,@ FINYR,@ INSTRUCTIO,@ RESEARCH,@ Public_SER,@ ACADEMIC_S,@ STUDENT_SE,@ INSTITUTIO ,@ PHYSICAL_P,@ NET_AID,@ AUXILIARY_,@ HEALTHPITALS,@ INDEPENDEN,@ OTEXEXP,@ TOTASSETS,@ TOTLIABILITY,@ NoNEXPPERMRESASSETS,@ EXPENDABLE,@ UNRNETASSETS,@ TOTALREV,@ TUITFEES,@ CURRDEBT,@ LongterMDEBT,@ TOTALNETASSETS)插入到表24(USERID,FirstName,MiddleName,LastName,Prefix,Suffix,Salutation,Title,Address1,Address2,City,State,Zip,Country,Phone,Fax,Email,DATE,accessLevel)值(@USIDID,@ FirstName,@ MiddleName,@ LastName,@ Prefix,@ Suffix,@ Sututation,@ Title,@ Address1,@ Address2,@ City,@ State,@ Zip,@ Country,@ Phone,@ Afax,@ Email,@ DATE,@ accessLevel) ,con);

cmd.CommandType = CommandType.Text;

cmd.Parameters.AddWithValue( @ TOTAL_REVE,TextBoxTRIR.Text );
cmd.Parameters.AddWithValue( @ USERID,TextBoxUSERID.Text);
cmd.Parameters.AddWithValue( @ INSTRUCTIO,TextBoxInstr.Text);
cmd.Parameters.AddWithValue( @ RESEARCH,TextBoxRes.Text);
cmd.Parameters.AddWithValue( @ PUBLIC_SER,TextBoxPubS.Text);
cmd.Parameters.AddWithValue( @ ACADEMIC_S,TextBoxAcad.Text);
cmd.Parameters.AddWithValue( @ STUDENT_SE,TextBoxStudS.Text);
cmd.Parameters.AddWithValue( @ INSTITUTIO,TextBoxInstiS.Text);
cmd.Parameters.AddWithValue( @ PHYSICAL_P,TextBoxOperM.Text);
cmd.Parameters.AddWithValue( @ NET_AID,TextBoxNGAS.Text);
cmd.Parameters.AddWithValue( @ AUXILIARY _,TextBoxAuxE.Text);
cmd.Parameters.AddWithValue( @ HOSPITALS,TextBoxHosS.Text);
cmd.Parameters.AddWithValue( @ INDEPENDEN,TextBoxIndeO.Text);
cmd.Parameters.AddWithValue( @ OTHEREXP,TextBoxOE.Text);
cmd.Parameters.AddWithValue( @ TOTASSETS,TextBoxTA.Text);
cmd.Parameters.AddWithValue( @ TOTLIABILITY,TextBoxTL.Text);
cmd.Parameters.AddWithValue( @NoNEXPPERMRESASSETS,TextBoxNPRNA.Text);
cmd.Parameters.AddWithValue( @ EXPENDABLE,TextBoxETRNA.Text);
cmd.Parameters.AddWithValue( @ UNRNETASSETS,TextBoxTUNA.Text);
cmd.Parameters.AddWithValue( @ TOTALREV,TextBoxTR.Text);
cmd.Parameters.AddWithValue( @ TUITFEES,TextBoxTFN.Text);
cmd.Parameters.AddWithValue( @ CURRDEBT,TextBoxCD.Text);
cmd.Parameters.AddWithValue( @ LONGTERMDEBT,TextBoxLTD.Text);
cmd.Parameters.AddWithValue( @ TOTALNETASSETS,TextBoxTNA.Text);
cmd.Parameters.AddWithValue( @ FINYR,TextBoxDATE2.Text);
cmd.Parameters.AddWithValue( @ DATE,TextBoxDATE.Text);

cmd.Parameters.AddWithValue( @ FirstName,TextBoxFName.Text );
cmd.Parameters.AddWithValue( @ LastName,TextBoxLName.Text);
cmd.Parameters.AddWithValue( @ MiddleName,TextBoxMName.Text);
cmd.Parameters.AddWithValue( @ Prefix,TextBoxPrefix.Text);
cmd.Parameters.AddWithValue( @ Suffix,TextBoxSuffix.Text);
cmd.Parameters.AddWithValue( @ Salutation,TextBoxSal.Text);
cmd.Parameters.AddWithValue( @ Title,TextBoxTitle.Text);
cmd.Parameters.AddWithValue( @ Address1,TextBoxMA1.Text);
cmd.Parameters.AddWithValue( @ Address2,TextBoxMA2.Text);
cmd.Parameters.AddWithValue( @ City,TextBoxCity.Text);
cmd.Parameters.AddWithValue( @ State,TextBoxState.Text);
cmd.Parameters.AddWithValue( @ Zip,TextBoxZip.Text);
cmd.Parameters.AddWithValue( @ Country,TextBoxCoun.Text);
cmd.Parameters.AddWithValue( @ Phone,TextBoxTN.Text);
cmd.Parameters.AddWithValue( @ Fax,TextBoxFN.Text);
cmd.Parameters.AddWithValue( @ Email,TextBoxEA.Text);
cmd.Parameters.AddWithValue( @ accessLevel,TextBoxaccessLevel.Text);

cmd.ExecuteNonQuery();
con.Close();

解决方案



I have a form that takes data and inserts it into three databases when the submit button is clicked. When a user clicks the submit button there are two inserts in two of the tables where there should be one insert per table. The last table is not getting any data at all. What did I do wrong?

protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand("Insert into Table22 (USERID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, NET_AID, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, TOTALNETASSETS) values (@USERID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @NET_AID, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @TOTALNETASSETS)Insert into Table23 (USERID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, NET_AID, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, TOTALNETASSETS) values (@USERID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @NET_AID, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @TOTALNETASSETS)Insert into Table24 (USERID, FirstName, MiddleName, LastName, Prefix, Suffix, Salutation, Title, Address1, Address2, City, State, Zip, Country, Phone, Fax, Email, DATE, accessLevel) values (@USERID, @FirstName, @MiddleName, @LastName, @Prefix, @Suffix, @Salutation, @Title, @Address1, @Address2, @City, @State, @Zip, @Country, @Phone, @Fax, @Email, @DATE, @accessLevel)", con);

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTRIR.Text);
        cmd.Parameters.AddWithValue("@USERID", TextBoxUSERID.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        cmd.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        cmd.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        cmd.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        cmd.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        cmd.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        cmd.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxOE.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);
        cmd.Parameters.AddWithValue("@TOTALNETASSETS", TextBoxTNA.Text);
        cmd.Parameters.AddWithValue("@FINYR", TextBoxDATE2.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);

        cmd.Parameters.AddWithValue("@FirstName", TextBoxFName.Text);
        cmd.Parameters.AddWithValue("@LastName", TextBoxLName.Text);
        cmd.Parameters.AddWithValue("@MiddleName", TextBoxMName.Text);
        cmd.Parameters.AddWithValue("@Prefix", TextBoxPrefix.Text);
        cmd.Parameters.AddWithValue("@Suffix", TextBoxSuffix.Text);
        cmd.Parameters.AddWithValue("@Salutation", TextBoxSal.Text);
        cmd.Parameters.AddWithValue("@Title", TextBoxTitle.Text);
        cmd.Parameters.AddWithValue("@Address1", TextBoxMA1.Text);
        cmd.Parameters.AddWithValue("@Address2", TextBoxMA2.Text);
        cmd.Parameters.AddWithValue("@City", TextBoxCity.Text);
        cmd.Parameters.AddWithValue("@State", TextBoxState.Text);
        cmd.Parameters.AddWithValue("@Zip", TextBoxZip.Text);
        cmd.Parameters.AddWithValue("@Country", TextBoxCoun.Text);
        cmd.Parameters.AddWithValue("@Phone", TextBoxTN.Text);
        cmd.Parameters.AddWithValue("@Fax", TextBoxFN.Text);
        cmd.Parameters.AddWithValue("@Email", TextBoxEA.Text);
        cmd.Parameters.AddWithValue("@accessLevel", TextBoxaccessLevel.Text);

        cmd.ExecuteNonQuery();
        con.Close();
解决方案



这篇关于将数据插入数据库两次,其他数据库中没有数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:12