5 Replies - 8648 Views - Last Post: 05 April 2011 - 12:37 PM Rate Topic: -----

#1 krista80   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 22-February 11

No mapping exists from object type error

Posted 05 April 2011 - 10:35 AM

This is the error I am getting:
No mapping exists from object type System.String[] to a known managed provider native type.

Source Error:


Line 77: sqlCmd.Parameters.Add(parA);
Line 78: sqlCmd.Parameters.Add(parI);
Line 79: sqlCmd.ExecuteNonQuery();
Line 80: sqlConn.Close();
Line 81: }

Source File: C:\FilePath\FTList.aspx.cs Line: 79

I have an ASP.NET web form with three multi-line text boxes. I need to get all the information out of these text boxes and save the info into a SQL Server database table. The coding for this looks like:
protected void bttnValid_Click(object sender, EventArgs e)
        {
            if (txtBoxFT.Text != "")
            {
                string[] lines = txtBoxFT.Text.Split('\n');
                string[] aLines = txtBoxA.Text.Split('\n');
                string[] iLines = txtBoxI.Text.Split('\n');

                foreach (string line in lines)
                {
                    string[] fTArray = line.Trim().Split('-');
                    string[] a = aLines;
                    string[] i = iLines;
                    LoadDataToDatabase(fTArray, a, i);
                }
                InsertData();
                DeleteData();
                Response.Redirect("~/Results.aspx");
            }
            else if (txtBoxFT.Text == "")
            {
                lblError.Text = "Please try again.";
            }
            else
            {
                lblError.Text = "An error occurred.";
            }
        }

The code for the LoadDataToDatabase looks like this:
private void LoadDataToDatabase(string[] fTArray, string[] a, string[] i)
        {
            string sqlTempQuery = string.Empty;
            StringBuilder sbTemp = new StringBuilder();

            SqlParameter parSess = new SqlParameter();
            parSess.ParameterName = "@Sess";
            parSess.Value = Session.SessionID;
            SqlParameter parB = new SqlParameter();
            parB.ParameterName = "@B";
            parB.Value = fTArray[0];
            SqlParameter parP = new SqlParameter();
            parP.ParameterName = "@P";
            parP.Value = fTArray[1];
            SqlParameter parBU = new SqlParameter();
            parBU.ParameterName = "@BU";
            parBU.Value = fTArray[2];
            SqlParameter parC = new SqlParameter();
            parC.ParameterName = "@C";
            parC.Value = fTArray[3];
            SqlParameter parA = new SqlParameter();
            parA.ParameterName = "@A";
            parA.Value = a;
            SqlParameter parI = new SqlParameter();
            parI.ParameterName = "@I";
            parI.Value = i;

            sbTemp.AppendFormat(string.Format(" INSERT INTO Temporary_Table "));
            sbTemp.AppendFormat(string.Format(" (SessionID, Temp_B, Temp_P, Temp_BU, Temp_C, Temp_A, Temp_I) "));
            sbTemp.AppendFormat(string.Format(" VALUES (@Sess, @B, @P, @BU, @C, @A, @I) "));

            sqlTempQuery = sbTemp.ToString();

            using (SqlConnection sqlConn = new SqlConnection(connectionString))
            {
              sqlConn.Open();

              SqlCommand sqlCmd = new SqlCommand(sqlTempQuery, sqlConn);
              sqlCmd.Parameters.Add(parSess);
              sqlCmd.Parameters.Add(parB);
              sqlCmd.Parameters.Add(parP);
              sqlCmd.Parameters.Add(parBU);
              sqlCmd.Parameters.Add(parC);
              sqlCmd.Parameters.Add(parA);
              sqlCmd.Parameters.Add(parI);
              sqlCmd.ExecuteNonQuery();
              sqlConn.Close();
          }
        }

The page worked fine before when I only had the one multi-line text box. I need to have all three in case someone has need of the A textbox or the I textbox. The program should still work if the textbox A or the textbox I are empty. Also, I need help with the foreach coding in the button handler. I have no idea how to get all the information from all three multi-line textboxes and have the information passed to the LoadDataToDatabase method at the same time.

Any help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: No mapping exists from object type error

#2 krista80   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 22-February 11

Re: No mapping exists from object type error

Posted 05 April 2011 - 11:30 AM

Also, I need to somehow trim the white space off the textBoxA and textBoxI numbers. How do I do this without having the .Split in the code?

Again. Any help is appreciated!
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: No mapping exists from object type error

Posted 05 April 2011 - 11:52 AM

Have a look at String.Trim
Was This Post Helpful? 1
  • +
  • -

#4 krista80   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 22-February 11

Re: No mapping exists from object type error

Posted 05 April 2011 - 11:58 AM

Thanks, AdamSpeight2008.
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: No mapping exists from object type error

Posted 05 April 2011 - 12:19 PM

Well, here's a problem:

parA.Value = a;


a is a string[], and there's no matching SQL data type. You need to either get a string out of the array, or concatenate all the array's indexes together into one string.
Was This Post Helpful? 1
  • +
  • -

#6 krista80   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 22-February 11

Re: No mapping exists from object type error

Posted 05 April 2011 - 12:37 PM

Thanks, Curtis. You were right. I forgot to add the [0] to the parA.Value.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1