Click here to Skip to main content
15,885,182 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questionerror: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
RAGHUNATH45616-Nov-17 4:31
RAGHUNATH45616-Nov-17 4:31 
AnswerRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Richard MacCutchan16-Nov-17 5:14
mveRichard MacCutchan16-Nov-17 5:14 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
RAGHUNATH45616-Nov-17 22:10
RAGHUNATH45616-Nov-17 22:10 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Richard MacCutchan16-Nov-17 22:40
mveRichard MacCutchan16-Nov-17 22:40 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Dominic Burford12-Dec-17 2:47
professionalDominic Burford12-Dec-17 2:47 
GeneralRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
tJackydx29-Nov-17 3:33
tJackydx29-Nov-17 3:33 
AnswerRe: error: The format of value 'application/json; charset=utf-8' is invalid. from webapi Pin
Dominic Burford12-Dec-17 2:46
professionalDominic Burford12-Dec-17 2:46 
QuestionProblem validating data input to a DataTable Pin
Ernesto R.D.8-Nov-17 17:54
Ernesto R.D.8-Nov-17 17: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 Vluggen8-Nov-17 23:45
professionalEddy Vluggen8-Nov-17 23:45 
GeneralRe: Problem validating data input to a DataTable Pin
Ernesto R.D.9-Nov-17 0:57
Ernesto R.D.9-Nov-17 0:57 
GeneralRe: Problem validating data input to a DataTable Pin
Eddy Vluggen9-Nov-17 2:49
professionalEddy Vluggen9-Nov-17 2:49 
QuestionCircle Progress in Visual Studio 2008 Pin
Member 135090597-Nov-17 16:25
Member 135090597-Nov-17 16:25 
AnswerRe: Circle Progress in Visual Studio 2008 Pin
Pete O'Hanlon7-Nov-17 21:47
mvePete O'Hanlon7-Nov-17 21:47 
AnswerRe: Circle Progress in Visual Studio 2008 Pin
Gerry Schmitz8-Nov-17 4:01
mveGerry Schmitz8-Nov-17 4:01 
GeneralRe: Circle Progress in Visual Studio 2008 Pin
Member 135090598-Nov-17 13:48
Member 135090598-Nov-17 13:48 
QuestionCast issue with CaptureFileAsync() Pin
MA-Navinn26-Oct-17 2:54
MA-Navinn26-Oct-17 2:54 
AnswerRe: Cast issue with CaptureFileAsync() Pin
Richard MacCutchan26-Oct-17 3:30
mveRichard MacCutchan26-Oct-17 3:30 
AnswerRe: Cast issue with CaptureFileAsync() Pin
Richard Deeming26-Oct-17 3:53
mveRichard Deeming26-Oct-17 3:53 
GeneralRe: Cast issue with CaptureFileAsync() Pin
MA-Navinn27-Oct-17 6:00
MA-Navinn27-Oct-17 6:00 
GeneralRe: Cast issue with CaptureFileAsync() Pin
MA-Navinn7-Nov-17 22:59
MA-Navinn7-Nov-17 22:59 
QuestionProcess data as you type Pin
Dirk Bahle13-Oct-17 8:21
Dirk Bahle13-Oct-17 8:21 
AnswerRe: Process data as you type Pin
Eddy Vluggen13-Oct-17 22:39
professionalEddy Vluggen13-Oct-17 22:39 
GeneralRe: Process data as you type Pin
Dirk Bahle14-Oct-17 1:34
Dirk Bahle14-Oct-17 1:34 
GeneralRe: Process data as you type Pin
Eddy Vluggen14-Oct-17 2:40
professionalEddy Vluggen14-Oct-17 2:40 
GeneralRe: Process data as you type Pin
Dirk Bahle14-Oct-17 7:27
Dirk Bahle14-Oct-17 7: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.