Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 880227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:03:43+00:00 2026-05-15T12:03:43+00:00

I am passing parameters to a stored proc. The parameters code block on the

  • 0

I am passing parameters to a stored proc.
The parameters code block on the asp.net side is:

SqlConnection con = new SqlConnection(strConn);  
string sqlItemSearch = "usp_Item_Search";  
SqlCommand cmdItemSearch = new SqlCommand(sqlItemSearch, con);  
cmdItemSearch.CommandType = CommandType.StoredProcedure;  

cmdItemSearch.Parameters.Add(new SqlParameter("@Item_Num", SqlDbType.VarChar, 30));  
cmdItemSearch.Parameters["@Item_Num"].Value = txtItemNumber.Text.Trim();  

cmdItemSearch.Parameters.Add(new SqlParameter("@Search_Type", SqlDbType.Int));  
cmdItemSearch.Parameters["@Search_Type"].Value = ddlSearchType.SelectedItem.Value;  

cmdItemSearch.Parameters.Add(new SqlParameter("@Vendor_Num", SqlDbType.VarChar, 10));  
cmdItemSearch.Parameters["@Vendor_Num"].Value = txtVendorNumber.Text.Trim();  

cmdItemSearch.Parameters.Add(new SqlParameter("@Search_User_ID", SqlDbType.Int));  
cmdItemSearch.Parameters["@Search_User_ID"].Value = ddlSeachUser.SelectedItem.Value;  

if (!string.IsNullOrEmpty(txtStartDate.Text))  
{  
    cmdItemSearch.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.DateTime));  
    cmdItemSearch.Parameters["@StartDate"].Value = Convert.ToDateTime(txtStartDate.Text.Trim());  
}  
else  
{  
    cmdItemSearch.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.DateTime));  
    cmdItemSearch.Parameters["@StartDate"].Value = Convert.ToDateTime("01/01/1996");  
}  

if (!string.IsNullOrEmpty(txtEndDate.Text))  
{  
    cmdItemSearch.Parameters.Add(new SqlParameter("@EndDate", SqlDbType.DateTime));  
    cmdItemSearch.Parameters["@EndDate"].Value = Convert.ToDateTime(txtEndDate.Text.Trim());  
}  
else  
{  
    cmdItemSearch.Parameters.Add(new SqlParameter("@EndDate", SqlDbType.DateTime));  
    cmdItemSearch.Parameters["@EndDate"].Value = Convert.ToDateTime(DateTime.Now);  
}  
con.Open();  

SqlDataAdapter ada = new SqlDataAdapter(cmdItemSearch);  
DataSet ds = new DataSet();  
ada.Fill(ds);  

gvSearchResults.DataSource = ds;  
gvSearchResults.DataBind();

I tried using

DateTime.ParseExact(this.Text,
“dd/MM/yyyy”, null);

but I get the same error.
The corressponding param in SQL is DateTime. I am currently passing blank fields for @StartDate and @EndDate, so the default values are passed as parameters. The error occurs at ada.Fill(ds) line. What would be causing the error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:03:44+00:00Added an answer on May 15, 2026 at 12:03 pm

    String was not recognized as a valid DateTime " format dd/MM/yyyy"

    this can help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am passing 4 Parameters to an asp.net Webservice. This is my Code so
I have a stored proc that I am passing two parameters into. One parameter
I have a new action in my controller that I'm passing parameters into so
We have an ASP.NET 2.0 application that uses Enterprise Library Data Access Application Block
I need to pass some parameters for a nested stored proc. Here is my
On my asp.net mvc page I need to render multiple images that are stored
I am passing form values to stored procedure parameters and it appears I may
I'm trying to convert some PHP code to a MySQL stored proc. Here's the
Does passing SQL Parameters to a stored procedure alone ensure that SQL injection won't
I am passing table field name as parameter to stored procedure but stored procedure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.