Click here to Skip to main content
13,763,464 members

.NET Framework

 
Questionerror: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
RAGHUNATH45616-Nov-17 5:31
memberRAGHUNATH45616-Nov-17 5:31 
AnswerRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Richard MacCutchan16-Nov-17 6:14
protectorRichard MacCutchan16-Nov-17 6:14 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
RAGHUNATH45616-Nov-17 23:10
memberRAGHUNATH45616-Nov-17 23:10 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Richard MacCutchan16-Nov-17 23:40
protectorRichard MacCutchan16-Nov-17 23:40 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Dominic Burford12-Dec-17 3:47
professionalDominic Burford12-Dec-17 3:47 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
tJackydx29-Nov-17 4:33
membertJackydx29-Nov-17 4:33 
AnswerRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Dominic Burford12-Dec-17 3:46
professionalDominic Burford12-Dec-17 3:46 
QuestionProblem validating data input to a DataTable Pin
Ernesto R.D.8-Nov-17 18:54
memberErnesto R.D.8-Nov-17 18:54 
Hello everyone, back to coding after a long absence so excuse my rustiness Sigh | :sigh:

When doing database apps ibe allways done the wrong thing & validated user input on the form, via simple checks against the controls .text property. Now i want to do it the right way, and concentrate all validation closer to the data side of things, in this case the data tables.
So i decided to do it via the RowChanging event:

On my table...
public override void EndInit()  
{  
    base.EndInit();  
    customersRowChanging += customersRowChangeEvent;  
}  

public void customersRowChangeEvent(object sender, customersRowChangeEvent e)  
{  
    if (e.Row.Name.Length == 0)  
    {  
        e.Row.SetColumnError("name", "Customer name cannot be empty");  
    }  
    else  
    {  
        e.Row.SetColumnError("name", "");  
    }  
}  



On my app, in a form the textboxes & other input are bound to a BindingSource, wich in turn is bound to the datatable in the dataset (100% as per visual studio designer).
To add a record,
I call the BindingSource.AddNew(), and allow the user to enter the data and then on my handler for the "Save" button...

try
     {
         Validate();
         customersBindingSource.EndEdit();
         customersTableAdapter.Update(samDataSet.customers);
         // other stuff here, close the form, etc.
     }
     catch(Exception ex)
     {
         // ... show a message box with the error.

     }


Even without handling the rowChange event, This works when a datatable or database constraint is violated, e.g. if the name is NULL or not unique (as specified in the data table constraints), an exception occurs, and the record is not saved.

However, Even with the RowChangeEvent implemented as above, if a record with an empty (not null, empty string) name is in the record, no exception is thrown, the datatable gladly accepts the new record, and the table adapter saves it (the MySQL database does not enforce empty string values).
Ibe checked, and the handler does get called, and the call to SetColumnError is made, but it doesnt prevent the table from accepting the new row.

I read to use this method from here: Validate data in datasets[^]
And i was under the impression that when i call SetColumnError() with a non empty string for error, the table would not accept the new row. Evidently i got it wrong.

Ibe also tried throwing an exception myself if the data fails the validation requirements, like this:
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)  
{  
    if (e.Row.Name.Length == 0)  
    {  
        e.Row.SetColumnError("name", "Customer name cannot be empty"); 
        throw new System.Exception("Customer Name cannot be empty"); 
    }  
    else  
    {  
        e.Row.SetColumnError("name", "");  
    }  
}  


But the Binding source does not catch & (re) throw the exception to my own code when it tries to commit the new record, because i end up with an unhandled exception.

Of course there are 101 ways i could enforce data validation on the form, or creating specific bool ValidateThis(DataRow theData) methods, but i would depend on calling such methods every time, and i would prefeer the tables to enforce their own rules automatically.

Can anyone see why its not working?
If calling the SetColumnError doesnt prevent the table from accepting the row, then whats the point of calling it to set errors?
Maybe im doing it the wrong way?
Any input much appreciated!

modified 9-Nov-17 0:27am.

AnswerRe: Problem validating data input to a DataTable Pin
Eddy Vluggen9-Nov-17 0:45
professionalEddy Vluggen9-Nov-17 0:45 
GeneralRe: Problem validating data input to a DataTable Pin
Ernesto R.D.9-Nov-17 1:57
memberErnesto R.D.9-Nov-17 1:57 
GeneralRe: Problem validating data input to a DataTable Pin
Eddy Vluggen9-Nov-17 3:49
professionalEddy Vluggen9-Nov-17 3:49 
QuestionCircle Progress in Visual Studio 2008 Pin
Member 135090597-Nov-17 17:25
memberMember 135090597-Nov-17 17:25 
AnswerRe: Circle Progress in Visual Studio 2008 Pin
Pete O'Hanlon7-Nov-17 22:47
protectorPete O'Hanlon7-Nov-17 22:47 
AnswerRe: Circle Progress in Visual Studio 2008 Pin
Gerry Schmitz8-Nov-17 5:01
memberGerry Schmitz8-Nov-17 5:01 
GeneralRe: Circle Progress in Visual Studio 2008 Pin
Member 135090598-Nov-17 14:48
memberMember 135090598-Nov-17 14:48 
QuestionCast issue with CaptureFileAsync() Pin
MA-Navinn26-Oct-17 3:54
memberMA-Navinn26-Oct-17 3:54 
AnswerRe: Cast issue with CaptureFileAsync() Pin
Richard MacCutchan26-Oct-17 4:30
protectorRichard MacCutchan26-Oct-17 4:30 
AnswerRe: Cast issue with CaptureFileAsync() Pin
Richard Deeming26-Oct-17 4:53
mvpRichard Deeming26-Oct-17 4:53 
GeneralRe: Cast issue with CaptureFileAsync() Pin
MA-Navinn27-Oct-17 7:00
memberMA-Navinn27-Oct-17 7:00 
GeneralRe: Cast issue with CaptureFileAsync() Pin
MA-Navinn7-Nov-17 23:59
memberMA-Navinn7-Nov-17 23:59 
QuestionProcess data as you type Pin
Dirk Bahle13-Oct-17 9:21
mvpDirk Bahle13-Oct-17 9:21 
AnswerRe: Process data as you type Pin
Eddy Vluggen13-Oct-17 23:39
professionalEddy Vluggen13-Oct-17 23:39 
GeneralRe: Process data as you type Pin
Dirk Bahle14-Oct-17 2:34
mvpDirk Bahle14-Oct-17 2:34 
GeneralRe: Process data as you type Pin
Eddy Vluggen14-Oct-17 3:40
professionalEddy Vluggen14-Oct-17 3:40 
GeneralRe: Process data as you type Pin
Dirk Bahle14-Oct-17 8:27
mvpDirk Bahle14-Oct-17 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181112.3 | Last Updated 12 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid