本文介绍了无法将参数值从字符串生成器转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,
我是uday satardekar,

我正在使用xml
插入12000行我正在使用xml绑定数据;
我正在使用StringBuilder

但是当我将其传递给标准过程时,它会引发异常
无法将参数值从字符串生成器转换为字符串

Hi sir ,
I am uday satardekar,

I am inserting 12000 rows using xml
and i am binding data using xml;
i am binging using StringBuilder

but when i am passing it to storded procedure it throws exception
Failed to convert parameter value from string builder to string

StringBuilder XML_TRANSACTIONDETAILS = new StringBuilder();

                    long maxid = getMaxId();

                    int status;

                    //XML_TRANSACTIONDETAILS = "<master>";
                    XML_TRANSACTIONDETAILS.Append("<master>");

                    for (int i = 0; i < excelRows; i++)
                    {
                             maxid = maxid + 1;

                           // XML_TRANSACTIONDETAILS = XML_TRANSACTIONDETAILS + "<TRANSACTION>";
                            //XML_TRANSACTIONDETAILS = XML_TRANSACTIONDETAILS + "<maxid>" + maxid + "</maxid>";
                             XML_TRANSACTIONDETAILS.Append("<TRANSACTION>");
                             XML_TRANSACTIONDETAILS.Append("<maxid>" + maxid + "</maxid>");

                            for (int j = 0; j < ExcelColumnCount; j++)
                            {
                                string xmlTag = cleanedEmailTbl.Columns[j].ToString();


                                XML_TRANSACTIONDETAILS.Append("<" + xmlTag + ">" + cleanedEmailTbl.Rows[i][j].ToString() + "</" + xmlTag + ">");
                           }

                            XML_TRANSACTIONDETAILS.Append("</TRANSACTION>");
                    }

                    XML_TRANSACTIONDETAILS.Append("</master>");

                    SqlParameter prm = new SqlParameter("@XML_TRANSACTIONDETAILS", SqlDbType.NText);
                    SqlParameter prm1 = new SqlParameter("@status", cmbAllStatus.SelectedValue);
                    SqlParameter prm2 = new SqlParameter("@username", currentLoggedUserId);
                    SqlParameter prm3 = new SqlParameter("@urlorcatalog", tboxUrlCat.Text);
                    SqlParameter prm4 = new SqlParameter("@dataentrytype", cmbDataEntryType.Text);



                    prm.Value = XML_TRANSACTIONDETAILS;

                    try
                    {
                        command.Connection = conn;
                        command.CommandText = "InsertExcelUsingXml";
                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.Add(prm);
                        command.Parameters.Add(prm1);
                        command.Parameters.Add(prm2);
                        command.Parameters.Add(prm3);
                        command.Parameters.Add(prm4);

                        adapter = new SqlDataAdapter(command);
                        adapter.Fill(ds1, "rowsinserted");

                        //after this lines exception comes


                        int rows1 = command.ExecuteNonQuery();
                        transaction.Commit();

推荐答案

prm.Value = XML_TRANSACTIONDETAILS.ToString();


这篇关于无法将参数值从字符串生成器转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 04:44