Click here to Skip to main content
15,895,772 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
The best overloaded method match for 'Class1.insertdata(string, System.DateTime, int, string, string, string)' has some invalid arguments   i want to insert dob

plz give suggestions

What I have tried:

Error: The best overloaded method match for 'Class1.insertdata(string, System.DateTime, int, string, string, string)' has some invalid arguments


Error at Convert.ToDateTime(txtdob.text)




class.cs
_________

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;


///
/// Summary description for Class1
///

public class Class1
{
DataClassesDataContext objlinq = new DataClassesDataContext();
Studentinfo objstu = new Studentinfo();

string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dbconnection"].ToString();

public void insertdata(string Name, DateTime Dob, int Mobile, string Email, string Username, string Password)
{
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spinsert";
con.Open();
cmd.Parameters.AddWithValue("Name", Name);
cmd.Parameters.AddWithValue("Dob", Dob);
cmd.Parameters.AddWithValue("Mobile",Mobile);
cmd.Parameters.AddWithValue("Email", Email);
cmd.Parameters.AddWithValue("Username",Username);
cmd.Parameters.AddWithValue("Password", Password);
cmd.ExecuteNonQuery();
con.Close();

}

button_click page
_________________


protected void btnsave_Click(object sender, EventArgs e)
{
Class1 objado = new Class1();
objado.insertdata(txtname.Text,Convert.ToDatetime(Txtdob.Text), Convert.ToInt64(Txtmbl.Text), Txtemail.Text, Txtuname.Text, Txtpass.Text);
Label1.Text = "data inserted success";
Response.Redirect("Login.aspx");
}
Posted
Comments
Richard Deeming 10-Feb-16 8:58am    
You appear to be storing passwords in plain text. That is a very bad idea. You should only ever store a salted hash of the password, using a unique salt per record.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

Also, spinsert is not a good name for your stored procedure. What are you inserting? What if you need to insert something else with a different stored procedure? Give it a meaningful name, like spInsertUser.

1 solution

Look at your code:
C#
public void insertdata(string Name, DateTime Dob, int Mobile, string Email, string Username, string Password)
And
C#
objado.insertdata(txtname.Text,Convert.ToDatetime(Txtdob.Text), Convert.ToInt64(Txtmbl.Text), Txtemail.Text, Txtuname.Text, Txtpass.Text);

Convert.ToInt64 does not produce an int - it produces a long.
As a result, it can't find a matching method signature, and complains.

But don't change the call to provide an int, or the method to access a long - neither is appropriate for a mobile number.
Firstly, because it implies that you can do arithmetic with them - and what is the product of adding your mobile number to mine? :laugh:
Secondly, because mobile numbers are often written with spaces and leading zeros, which should be preserved. Storing them in a numeric field will either mean the conversion fails, or gives the wrong value.

Instead, change you DB to store mobile numbers in a string field, and pass strings instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900