Quote:
every thing is correct but except data pivker
This means that you need to figure out and handle the value being assigned to datapicker. Above code is not responsible for its NULL value. Though, since it's null, trying to use ToString on it will raise an error "Object reference not set to an instance".
This is one of the common errors asked here - Null reference exception.
Details about the error you see:
NullReferenceException Class (System) | Microsoft Docs[
^]
Quote:
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null
Possibly because:
1. You've forgotten to instantiate a reference type
2. You've forgotten to dimension an array before initializing it.
3. You get a null return value from a method, and then call a method on the returned type.
4. You're using an expression (for example, you're chaining a list of methods or properties together) to retrieve a value
5. You're enumerating the elements of an array that contains reference types, and your attempt to process one of the elements throws
6. Exception is thrown by a method that is passed null
When you debug, you will be able to get the exact line where the variable is NULL and error is being raised. Find why it's null and handle it.
Other response here has already shard about the SQL injection issue that you need to handle as best practice.
Try out.