Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 datime error in my SP Class

Author  Topic 

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-18 : 14:10:45
hello
I have a class below which calls a SP. But in the datetime value, it gives an error

Any advice on this

Below is my class and .net c# web page. Error line is in red below.
thanks
Ehi

   <form id="form1" runat="server">
<div>

<asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:TextBox ID="First_Name" runat="server"></asp:TextBox>
<asp:TextBox ID="dob" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

</div>
</form>




and here is my code in my class



command.Parameters.Add(new SqlParameter("@usernames", SqlDbType.Int, 0, "RegionID"));
command.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar, 20, "username"));
command.Parameters.Add(new SqlParameter("@First_Name", SqlDbType.VarChar, 50, "First_Name"));
command.Parameters.Add(new SqlParameter("@Last_Name", SqlDbType.VarChar, 50, "Last_Name"));
command.Parameters.Add(new SqlParameter("@dob", SqlDbType.Date, 50, "dob"));

command.Parameters[0].Value = 4;
command.Parameters[1].Value = "username";
command.Parameters[2].Value = "First_Name";
command.Parameters[3].Value = "Last_Name";
command.Parameters[4].Value = DateTime.Parse(dob.Text);

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2008-01-18 : 15:11:19
looks like u aren't passing in a valid date
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-18 : 15:17:15
I get the error, before the page loads.

Am not given a chance to pass the date accross.


Compiler Error Message: CS0103: The name 'dob' does not exist in the current context

Source Error:



Line 46: command.Parameters[2].Value = "First_Name";
Line 47: command.Parameters[3].Value = "Last_Name";
Line 48: command.Parameters[4].Value = DateTime.Parse(dob.Text);
Line 49:
Line 50: int i = command.ExecuteNonQuery();


Source File: c:\inetpub\wwwroot\cellulant1\App_Code\signup_data-entry.cs Line: 48
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2008-01-18 : 16:54:12
//// sorry stupid reply edited out ///
Go to Top of Page

mukunda
Starting Member

4 Posts

Posted - 2008-01-24 : 07:00:59
first try to convert textbox value to the correct datetime formate. by using date.parse() or convert.datetime() these function if its success fully converted then pass to the command parameter

datetime dt=convert.ToDateTime(txtdate.text)

or
dt= date.Parse(txtdate.txt)
if it runs without exception then it will work fine if exception you r passing invalid data.

Thanks
Mukund
Go to Top of Page

JBelthoff
Posting Yak Master

173 Posts

Posted - 2008-01-26 : 08:08:52
Are you using Asp.net 1.1 or 2.0?

Because you are getting this error before the page loads, it sounds like you are using 1.1.

In that case you have to declare the control as protected in your code behind.

There error "Compiler Error Message: CS0103: The name 'dob' does not exist in the current context" means exactly what it says. That reference does not exists.

My guess is if you wrote the other parameter values correctly like this:

command.Parameters[1].Value = username.Text;
command.Parameters[2].Value = First_Name.Text;
command.Parameters[3].Value = Last_Name.Text;

You would find similar errors there as well.

State what version you are using and post all of your code and I could narrow this down a little better.






JBelthoff
• Hosts Station is a Professional Asp Hosting Provider
› As far as myself... I do this for fun!
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-01-28 : 05:02:45
Sorry guys,
i didnt get an alert mail from your posts.

You are right, i left it out in the reference passed to the method.

 public new_users_signup(string First_Name1,dob etc....


its fixed now
thanks
Go to Top of Page
   

- Advertisement -