'class1.insertdata(string,system.datetime,int,string,string,string)'的最佳重载方法匹配有一些我想插入dob的无效参数 [英] The best overloaded method match for 'class1.insertdata(string, system.datetime, int, string, string, string)' has some invalid arguments i want to insert dob
问题描述
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给出建议
我尝试过:
错误:'Class1.insertdata(string,System.DateTime,int,string,string,string)'的最佳重载方法匹配有一些无效的参数
Convert.ToDateTime(txtdob.text)出错
class.cs
_________
使用System;
使用System.Collections。 Generic;
使用System.Linq;
使用System.Web;
使用System.Data;
使用System.Data.SqlClient;
///< summary>
///摘要描述Class1
///
公共类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(Mobil e,移动);
cmd.Parameters.AddWithValue(电子邮件,电子邮件);
cmd.Parameters.AddWithValue(用户名,用户名);
cmd.Parameters.AddWithValue(密码,密码);
cmd.ExecuteNonQuery();
con.Close();
}
button_click page
_________________
< br $>
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 =数据插入成功;
Response.Redirect(Login.aspx);
}
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>
/// 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");
}
推荐答案
查看您的代码:
Look at your code:
public void insertdata(string Name, DateTime Dob, int Mobile, string Email, string Username, string Password)
和
And
objado.insertdata(txtname.Text,Convert.ToDatetime(Txtdob.Text), Convert.ToInt64(Txtmbl.Text), Txtemail.Text, Txtuname.Text, Txtpass.Text);
Convert.ToInt64不产生 int
- 它产生一个长
。
因此,它无法找到匹配的方法签名,并抱怨。
但是不要更改提供 int
的调用,或者访问 long $ c $的方法c> - 两者都不适合手机号码。
首先,因为这意味着你可以对它们进行算术运算 - 以及将你的手机号码添加到我的手机号码的产品是什么? :笑:
其次,因为手机号码通常是用空格和前导零写的,应该保留。将它们存储在数字字段中将意味着转换失败,或者给出错误的值。
而是将数据库更改为在字符串字段中存储移动号码,并且改为传递字符串。
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.
这篇关于'class1.insertdata(string,system.datetime,int,string,string,string)'的最佳重载方法匹配有一些我想插入dob的无效参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!