Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

this code for a parameterized update query is giving me an error that i can't figure out what the problem is. my code:

 

updateCommand1 = New OleDb.OleDbCommand("INSERT INTO Event_Nuclear (SS_Patient_ID, EventAge, Weight, Height, StudyType, EventDate,StudyNumber, PILocation, Indication) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", Me.OleDbConnection1)

           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("PID", OleDb.OleDbType.Numeric, 10))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("EventAge", OleDb.OleDbType.Numeric, 3))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Weight", OleDb.OleDbType.Numeric, 3))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Height", OleDb.OleDbType.Numeric, 3))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("StudyType", OleDb.OleDbType.VarChar, 40))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("RNADate", OleDb.OleDbType.Date))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("StudyNo", OleDb.OleDbType.VarChar, 15))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Location", OleDb.OleDbType.VarChar, 30))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Indication", OleDb.OleDbType.Numeric))
           updateCommand1.Prepare()

 

 

the error:

 

System.InvalidOperationException: OleDbCommand.Prepare method requires parameters of type '131' have an explicitly set Precision and Scale.
  at System.Data.OleDb.OleDbParameter.Prepare(OleDbCommand cmd)
  at System.Data.OleDb.OleDbCommand.PrepareCommandText(Int32 expectedExecutionCount)
  at System.Data.OleDb.OleDbCommand.Prepare()

 

is my query wrong? any ideas?

Posted

are your Numerics really numerics, or can you get away with specifiying them as integers????

 

          updateCommand1.Parameters.Add(New OleDb.OleDbParameter("PID", OleDb.OleDbType.Integer))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("EventAge", OleDb.OleDbType.Integer))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Weight", OleDb.OleDbType.Integer))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Height", OleDb.OleDbType.Integer))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("StudyType", OleDb.OleDbType.VarChar, 40))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("RNADate", OleDb.OleDbType.Date))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("StudyNo", OleDb.OleDbType.VarChar, 15))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Location", OleDb.OleDbType.VarChar, 30))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Indication", OleDb.OleDbType.Integer))
           updateCommand1.Prepare()

should work. . .

 

else, you will have to specify precision/scale before preparing:

 

           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("PID", OleDb.OleDbType.Numeric))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("EventAge", OleDb.OleDbType.Numeric))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Weight", OleDb.OleDbType.Numeric))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Height", OleDb.OleDbType.Numeric))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("StudyType", OleDb.OleDbType.VarChar, 40))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("RNADate", OleDb.OleDbType.Date))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("StudyNo", OleDb.OleDbType.VarChar, 15))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Location", OleDb.OleDbType.VarChar, 30))
           updateCommand1.Parameters.Add(New OleDb.OleDbParameter("Indication", OleDb.OleDbType.Numeric))

// Specify Precision and size for numerics:
           updateCommand1.Parameters["PID"].Precision = {some precision};
           updateCommand1.Parameters["PID"].Scale = {some scale};
           updateCommand1.Parameters["EventAge"].Precision = {some precision};
           updateCommand1.Parameters["EventAge"].Scale = {some scale};
           updateCommand1.Parameters["Weight"].Precision = {some precision};
           updateCommand1.Parameters["Weight"].Scale = {some scale};
           updateCommand1.Parameters["Height"].Precision = {some precision};
           updateCommand1.Parameters["Height"].Scale = {some scale};
           updateCommand1.Parameters["Indication"].Precision = {some precision};
           updateCommand1.Parameters["Indication"].Scale = {some scale};

// now prepare
           updateCommand1.Prepare()

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...