C# 重载问题

summersnow_ay 2009-05-18 10:48:22
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace NewStudentsRegisterinfo
{
public partial class FormEdit : Form
{
public FormEdit()
{
InitializeComponent();
}

private void btnEdit_Click(object sender, EventArgs e)
{
StudentDBUtil.StudentRegisterEdit(
tbxID.Text ,
tbxName.Text,
cbxGender.Text,
dtpBirthday.Text,
tbxProvince.Text,
dtpRegDate.Text,
cbxCollege.Text,
nudRegGrade.Value.ToString());
MessageBox.Show(tbxName.Text + "修改成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void btnSearch_Click(object sender, EventArgs e)
{
DataSet dsStuedent = StudentDBUtil.StudentEditQuery(tbxName.Text, "Student");
if (dsStuedent.Tables["Student"] != null)
{
if (dsStuedent.Tables["Student"].Rows.Count > 0)
{
tbxID.Text = dsStuedent.Tables["Student"].Rows[0]["ID"].ToString();
tbxName.Text = dsStuedent.Tables["Student"].Rows[0]["Name"].ToString();
cbxGender.Text = dsStuedent.Tables["Student"].Rows[0]["Gender"].ToString();
dtpBirthday.Value = Convert.ToDateTime(dsStuedent.Tables["Student"].Rows[0]["Birthday"].ToString());
tbxProvince.Text = dsStuedent.Tables["Student"].Rows[0]["Province"].ToString();
dtpRegDate.Value = Convert.ToDateTime(dsStuedent.Tables["Student"].Rows[0]["RegDate"].ToString());
cbxCollege.Text = dsStuedent.Tables["Student"].Rows[0]["RegCollege"].ToString();
nudRegGrade.Value = Convert.ToInt32(dsStuedent.Tables["Student"].Rows[0]["RegGrade"].ToString());
}
}
}
}
}
错误 1 “StudentRegister”方法没有采用“7”个参数的重载
...全文
156 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
summersnow_ay 2009-05-19
  • 打赏
  • 举报
回复
继续补充:StudentDBUtil代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace NewStudentsRegisterinfo
{
class StudentDBUtil
{
public static void StudentRegister(
string strID,
string strName,
string strGender,
string strBrithday,
string strProvince,
string strRegDate,
string strRegCollege,
string strRegGrade)
{
string strCmd = "INSERT INTO REGISTERINFO" + "(ID,NAME,GENDER,BIRTHDAY,PROVINCE,REGDATE,REGCOLLEGE,REGGRADE)" + "VALUES"
+ "('"+strID+"','"+strName+"','"+strGender+"','"+strBrithday+"','"+strProvince+"','"+strRegDate+"','"+strRegCollege+"', '"+strRegGrade+"')";
DBUtil.SqlExecuteNonQuery(strCmd);
}
public static DataSet StudentQuery(string strName, string strTableName)
{
string strCmd = "SELECT ID,NAME,GENDER,BIRTHDAY,PROVINCE,REGDATE,REGCOLLEGE,REGGRADE" + "FROM REGISTERINFO";
if (!strName.Equals(""))
{
strCmd += "WHERE NAME LIKE '%" + strName + "%'";
}
return DBUtil.GetDataSet(strCmd, strTableName);
}
public static DataSet StudentEditQuery(string strName, string strTableName)
{
string strCmd = "SELECT TOP1 ID,NAME,GENDER,BIRTHDAY,PROVINCE,REGDATE,REGCOLLEGE,REGGRADE" + "FROM REGISTERINFO"
+ "WHERE NAME = '" + strName + "'";
return DBUtil.GetDataSet(strCmd, strTableName);
}
public static void StudentRegisterEdit(
string strID,
string strName,
string strGender,
string strBirthday,
string strProvince,
string strRegDate,
string strRegCollege,
string strRegGrade)
{
string strCmd = "UPDATE REGISTERINFO SET" +
"NAME = '" + strName + "'," +
"GENDER = '" + strGender + "', " +
"BIRTHDAY = '" + strBirthday + "', " +
"PROVINCE = '" + strProvince + "', " +
"REGDATE = '" + strRegDate + "', " +
"REGCOLLEGE = '" + strRegCollege + "', " +
"REGGRADE = ' " + strRegGrade + " " +
"WHERE ID=" + strID;
DBUtil.SqlExecuteNonQuery(strCmd);
}
}
}
summersnow_ay 2009-05-19
  • 打赏
  • 举报
回复
补充:StudentDBUtil代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace NewStudentsRegisterinfo
{
class DBUtil
{
public static int SqlExecuteNonQuery(SqlCommand objCommand)
{
string strConnect = "Data Source=localhost;DataBase=StudentDB;uID=sa;pwd=";
SqlConnection objConnection = new SqlConnection(strConnect);
objCommand.Connection = objConnection;
try
{
if (objConnection.State == ConnectionState.Closed)
{
objConnection.Open();
}
return objCommand.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
if (objConnection.State == ConnectionState.Open)
{
objConnection.Close();
}
}
}
public static int SqlExecuteNonQuery(string strCmd)
{
SqlCommand objCommand = new SqlCommand(strCmd);
return SqlExecuteNonQuery(objCommand);
}
public static object SqlExecuteScalar(SqlCommand objCommand)
{
string strConnect = "Data Source=localhost;DataBase=StudentDB;uID=sa;pwd=";
SqlConnection objConnection = new SqlConnection(strConnect);
objCommand.Connection = objConnection;
try
{
if (objConnection.State == ConnectionState.Closed)
{
objConnection.Open();
}
return objCommand.ExecuteScalar();
}
catch (Exception e)
{
throw e;
}
finally
{
if (objConnection.State == ConnectionState.Open)
{
objConnection.Close();
}
}
}
public static object SqlExecuteScalar(string strCmd)
{
SqlCommand objCommand = new SqlCommand(strCmd);
return SqlExecuteScalar(objCommand);
}
public static DataSet GetDataSet(SqlCommand objCommand, string strTableName)
{
string strConnect = "Data Source=localhost;DataBase=StudentDB;uID=sa;pwd=";
SqlConnection objConnection = new SqlConnection(strConnect);
objCommand.Connection = objConnection;
try
{
if (objConnection.State == ConnectionState.Closed)
{
objConnection.Open();
}
SqlDataAdapter objDataAdapter = new SqlDataAdapter(objCommand);
DataSet objDataSet = new DataSet();
objDataAdapter.Fill(objDataSet, strTableName);
return objDataSet;
}
catch (Exception e)
{
throw e;
}
finally
{
if (objConnection.State == ConnectionState.Open)
objConnection.Close();
}
}
public static DataSet GetDataSet(string strCmd, string strTableName)
{
SqlCommand objCommand = new SqlCommand(strCmd);
return GetDataSet(objCommand, strTableName);
}
}
}
binhu12332100 2009-05-19
  • 打赏
  • 举报
回复
建议你先查看一下StudentRegister这个方法是否是需要7个参数,要是参数的个数或是类型不对的话,那是肯定不行的……
zhushoudong 2009-05-18
  • 打赏
  • 举报
回复
帮顶一下
tmd456 2009-05-18
  • 打赏
  • 举报
回复
先查看一下StudentRegister这个方法是否是需要7个参数
Dhoopu 2009-05-18
  • 打赏
  • 举报
回复
wangxinli_nissan 2009-05-18
  • 打赏
  • 举报
回复
同意1楼的说法,先查看一下StudentRegister这个方法是否是需要7个参数
dsr456 2009-05-18
  • 打赏
  • 举报
回复
查看一下 StudentDBUtil这个类的方法先

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧