Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

zero length string HELP!!!!!

Status
Not open for further replies.

length

Technical User
Dec 4, 2004
7
JO
I am trying to write user input data on a dialog box into Access Database and i getting an error saying " cannot be a zero length string".

my code...

// variable iniat.
m_Item_Name = _T("");
m_Item_Price = COleCurrency(0,0);

//map...in C++ data exchange

DDX_Text(PDX,IDC_item, m_Item_Name);
DDX_Text(PDX,IDC_price, m_Item_Price);

// writeing to record.

recordSet.m_item = m_Item_Name;
recordSet.m_price = m_Iitem_price;

pls tel me where i am going wrong, i tried the program by replacing the item_name field with "Cup" woorks fine,
but i still get error if replaced the price with 2.50, an error saying "binary = "


please Help....
thanks.
 
2 questions, the error you get, "cannot be a zero length string" I am asuming it is the Access Error box, a runtime error box with a red X in it?

If so, I believe your DDX is not being called. Do you use CDialog::OnOk or do you call UpdateData(TRUE)?

As for this error "but i still get error if replaced the price with 2.50, an error saying "binary = ""

Is that a runtime error or a compiler error? I don't know much about OLECurrency, but if it is a runtime error, I may be able to help.

CJB
 
I am using CDialog. What i have is the following.

void CAddItem::OnAddNewItem()
{
AddItemNew();
}

int CAddItem::AddItemNew()
{
m_Item_Name = _T("");
m_Item_Price = COleCurrency(0,0);

DDX_Text(PDX,IDC_item, m_Item_Name);
DDX_Text(PDX,IDC_price, m_Item_Price);

// writeing to record.
// do db connection
recordSet.AddNew();
recoredSet.Edit();
recordSet.m_item = m_Item_Name;
recordSet.m_price = m_Iitem_price;
UpdateData(TRUE) //does not work or FALSE.
recordSet.Update(); //Works only if add values within
program as above
}
recordSet.Close();


 
The first thing that jumps out at me is you call AddNew() and then Edit(). You only need to call AddNew() if you want to add a record. This might lead to the error you are reciving. If that doesn't work, abandon UpdateData and DDC_Text. This might sound like a cop out, but that is what I do to avoid errors. When I add new or Edit(), I always explicitly assign a value to each member of my data set. This is made easier by using control variabls. Like

CEdit c_Profit;//Make this global for the dlg

DDX_Control(pDX, IDC_PROFIT, c_Profit);
recordSet.Open();
recordSet.AddNew();
c_Profit.GetWindowText(recordSet.m_Profit);
recordSet.Update();

or if recordSet.m_Profit is an int or double, like it probably is, do

CString string;
c_Profit.GetWindowText(string);
recordSet.m_Profit = atof(string);

Does that make sense?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top