none
storing/inserting data into table using a tableadapter (2nd try) RRS feed

  • Question

  • i've created a form and now im trying to store data into table.

    i keep getting converting and syntax errors and i don't know how to fix this problem.

    this is what i have and tried.

    //============================================================================

    // created table adapter for new purchase requisition.

    //============================================================================

    Data_Access.dsBudgetTableAdapters.tbl_purchaseReqTableAdapter pr =

    new Data_Access.dsBudgetTableAdapters.tbl_purchaseReqTableAdapter();

     

    pr.InsertPayee(Convert.ToInt32(txtPRNum.Text), Convert.ToString(drpStaffID.SelectedIndex), txtDate, txtWpm, drpPurchaseAuth, txtAmount, txtDescription, drpTaxable, drpOMWBE, txtAttn, txtPurpose, chkActual, chkEstimate, drpPayee);

     

    Im getting these errors:

     

    cannont convert from system.web.ui.webcontrols.textbox to system.datetime

    cannont convert from system.web.ui.webcontrols.textbox to string

    cannont convert from system.web.ui.webcontrols.dropdownList to string

    cannont convert from system.web.ui.webcontrols.DropDownList to bool

    cannont convert from system.web.ui.webcontrols.checkbox to bool

    cannont convert from system.web.ui.webcontrols.dropdown to system.guid?

     

    I am guessing i need to figure out a way to convert and cast?

     

    any help? im new to c# and vs

    Monday, June 25, 2007 9:07 PM

Answers

  • I already write you how to do that. But when you solve this error, don't hope your code will work. You must first learn what is SelectedItem, SelectedValue, SelectedIndex, Text properties of comboboxes. SelectedIndex as you used are not usefull for your scenario. If your combo is connected to some source table and you show in drpPayee one thing like Payee Name as DisplayMember and guid id for Payee ID as ValueMember then SelectedValue should be used as i write in my previous post.
    Also usefull thing in development is to put a breakpoint on line and see which of these properties SelectedItem, SelectedValue, Text are filled and to change your code to use right properties. Which properties will be usefull depends of how you use combobox. There are two ways, connected and disconnected, that cause different properties to be used.
    Wednesday, June 27, 2007 7:39 AM

All replies

  • i've created a form and now im trying to store data into table.

    i keep getting converting and syntax errors and i don't know how to fix this problem.

    this is what i have and tried.

    //============================================================================

    // created table adapter for new purchase requisition.

    //============================================================================

    Data_Access.dsBudgetTableAdapters.tbl_purchaseReqTableAdapter pr =

    new Data_Access.dsBudgetTableAdapters.tbl_purchaseReqTableAdapter();

     

    pr.insertPayee((int)txtPRNum.Text), (int) drpStaffID.SeletedIndex, txtDate,chkActual,chkEst);

     

    any ideas?

    Monday, June 25, 2007 6:49 PM
  • try this  replace (int) with Convert.ToInt16(value to convert)

    -paul

    Monday, June 25, 2007 7:24 PM
  • thx for your reply Paul.  I am getting few more errors though

     

    cannont convert from system.web.ui.webcontrols.textbox to system.datetime

    cannont convert from system.web.ui.webcontrols.textbox to string

    cannont convert from system.web.ui.webcontrols.dropdownList to string

    cannont convert from system.web.ui.webcontrols.DropDownList to bool

    cannont convert from system.web.ui.webcontrols.checkbox to bool

    cannont convert from system.web.ui.webcontrols.dropdown to system.guid?

     

    this is what i have .

     

    pr.InsertPayee(Convert.ToInt32(txtPRNum.Text), Convert.ToString(drpStaffID.SelectedIndex), txtDate, txtWpm, drpPurchaseAuth, txtAmount, txtDescription, drpTaxable, drpOMWBE, txtAttn, txtPurpose, chkActual, chkEstimate, drpPayee);

     

    any syntax helps? im new to c# and vs

    Monday, June 25, 2007 8:03 PM
  • It looks like you are getting the errors because your referencing the control  as a whole rather than just the text / DateTime portions that you want.

     

    Try somthing like

     

    pr.InsertPayee(Convert.ToInt32(txtPRNum.Text), Convert.ToString(drpStaffID.SelectedIndex), txtDate.Text, txtWpm.Text, drpPurchaseAuth.SelectedValue.ToString(), txtAmount.Text, txtDescription.Text, drpTaxable.SelectedValue.ToString(), drpOMWBE.SelectedValue.ToString(), txtAttn.Text, txtPurpose.Text, chkActual.Checked, chkEstimate.Checked, drpPayee.SelectedValue.ToString());

     

     

    Thats probably not exactly right but it should point you in the right direction.

    Monday, June 25, 2007 10:44 PM
  • What you need to be doing i casting the contents to their types like so

     

    drpPurchaseAuth.SelectItem.Text.ToString(); - returns string value

     

    most likely you need a variable of type bool here. You could also go off the selected index for this one. Replace the parameter drpTaxable with the variable taxable

     

    bool taxable = false;

    if (drpTaxable.SelectedItem.Text == "True")

    {

      taxable = true;

    }

     

    chkActual.Checked(); - returns bool value

     

    drpPayee I assume shows a users name, but what you will need to do is have the Value property set to the GUID for the user so that you can retrieve the GUID out by casting the ValueMember  ToGUID.

     

    This should help clear up some more. i am not sure what controls all the errors go to so I picked out what I thought were the obvious ones.

     

    -paul

    Tuesday, June 26, 2007 3:01 AM
  • You can't just use txtDate or txtWmp or other controls by their name. You must read it's value property, Text or SelectedItem or Checked or SelectedValue or Value. It all depends on control type. By the errors you need except read entered value by the correct property of control, for some of them do additional conversion in order to corespond with parameters of the InsertPayee method. That is the case for datetime, bool and guid value.
    So to get datetime value from text control you will probably to something like this: DateTime.ParseExact(txtDate.Text, "MM/dd/yyyy", CultureInfo.CurrentCulture
      for bool value needed from dropdownlist: Convert.ToBoolean(drpPurchaseAuth.SelectedValue)
      for checkbox you will just use Checked Property  chkActual.Checked
      for guid value you will probably have     new Guid(drpPayee.SelectedValue.ToString())
    Tuesday, June 26, 2007 7:00 AM
  • use the inline statements which is commented in red color

     

     shy216 wrote:

    thx for your reply Paul.  I am getting few more errors though

     

    cannont convert from system.web.ui.webcontrols.textbox to system.datetime

    cannont convert from system.web.ui.webcontrols.textbox to string

    cannont convert from system.web.ui.webcontrols.dropdownList to string

    cannont convert from system.web.ui.webcontrols.DropDownList to bool

    cannont convert from system.web.ui.webcontrols.checkbox to bool

    cannont convert from system.web.ui.webcontrols.dropdown to system.guid?

     

    this is what i have .

     

    pr.InsertPayee(Convert.ToInt32(txtPRNum.Text), Convert.ToString(drpStaffID.SelectedIndex), txtDate.Text, txtWpm.Text, drpPurchaseAuth.SelectedItem, txtAmount.Text, txtDescription.Text, drpTaxable.SelectedItem, drpOMWBE.SelectedItem, txtAttn.Text, txtPurpose.Text, chkActual, chkEstimate, drpPayee.SelectedItem);

     

    any syntax helps? im new to c# and vs

     

    Give me the InsertPayee method arguments with the corresponding datatypes. so that i can give you the correct code to work.

    Tuesday, June 26, 2007 7:14 AM
  • First, thank you for your reply

     

    This is the SQL of InsertPayee()

     

    INSERT INTO tbl_PurchaseRequisition
                          (PrNum, StaffID, Date, WPM, WPMRefNum, Amount, Description, TaxChrg, OMWABE, ATTN, PurposeOfPurchase, Actual, Estimate, paid)
      VALUES     (@PrNum,@StaffID,@Date,@WPM,@WPMRefNum,@Amount,@Description,@TaxChrg,@OMWBE,@Attn,@PurposeofPurchase,@Acutal,@Est,@paid)

     

    //Datatypes=========

    PrNum=system.int32  ,   StaffID=system.string   ,  Date=system.DateTime  ,  WPM=system.string  ,  WPMRefNum=system.string  ,

    amount=system.decimal  ,  Description=system.string  ,  taxChrg=system.boolean  ,  OMWABE=system.string  ,  Attn=system.string  ,

    PurposeofPurchase=system.string   ,  actual=system.boolean  ,  Estimate=system.boolean  ,  paid =system.guid

     

     

    * this is what i currently have now..

     

    pr.InsertPayee(Convert.ToInt32(txtPRNum.Text), Convert.ToString(drpStaffID.SelectedIndex), Convert.ToDateTime(txtDate.Text), txtWpm.Text, Convert.ToString(drpPurchaseAuth.SelectedIndex), Convert.ToDecimal(txtAmount.Text), txtDescription.Text,Convert.ToBoolean(drpTaxable.Text) , Convert.ToString(drpOMWBE.SelectedIndex), txtAttn.Text, txtPurpose.Text, chkActual.Checked, chkEstimate.Checked,drpPayee.SelectedIndex.ToString);

     

     i am getting 2 errors.

     

    The best overloaded method match for 'PurchaseReq.data_access.dsbudgettableadapters.tbl_purchaseReqTableAdapter.InsertPayee(int,string,system.datetime?,string,string,decimal?,string,bool,string,string,string,bool,bool,system.guid?) has some invalid arguments

    and

    argument'14': cannot convert from 'method group' to 'system.guid?'

    Tuesday, June 26, 2007 8:22 PM
  • Merged the two threads which have the same topic, so all information about this problem will be in the same location.
    Wednesday, June 27, 2007 3:12 AM
  • I already write you how to do that. But when you solve this error, don't hope your code will work. You must first learn what is SelectedItem, SelectedValue, SelectedIndex, Text properties of comboboxes. SelectedIndex as you used are not usefull for your scenario. If your combo is connected to some source table and you show in drpPayee one thing like Payee Name as DisplayMember and guid id for Payee ID as ValueMember then SelectedValue should be used as i write in my previous post.
    Also usefull thing in development is to put a breakpoint on line and see which of these properties SelectedItem, SelectedValue, Text are filled and to change your code to use right properties. Which properties will be usefull depends of how you use combobox. There are two ways, connected and disconnected, that cause different properties to be used.
    Wednesday, June 27, 2007 7:39 AM