您当前的位置: 百科371电脑/网络C#/.NET → 电脑/网络内容 退出登录 用户管理 用户注册
本类热门文章
相关文章
中原建材网
一个C#的问题~

减小字体 增大字体

问题:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace a{ public partial class Form1 : Form { SqlConnection con; SqlCommand cmd; SqlDataReader dataReader; public Form1() { InitializeComponent(); } private void toolStripButton2_Click(object sender, EventArgs e) { int id = Convert.ToInt32(((ToolStripButton)sender).Tag); //收件箱到tag是1,垃圾箱到tag是0 if (id == 1) { this.Text = GreenMail收件箱; } else if(id==0) { this.Text = GreenMail垃圾箱; } GetMail(id); //收件箱和垃圾箱共用tooStripButton2_click这一个方法,如果点击收件箱,把1传过去,如果点击垃圾箱,把0传过去, } private void toolStripButton4_Click(object sender, EventArgs e) { this.Close(); } private void Form1_Load(object sender, EventArgs e) { con = new SqlConnection(Data Source=.;Initial Catalog=GreenMail;Integrated Security=True); } public int GetMail(int id) { string Receiver=; string Acceptor=; string Subject=; string Date=; string sql = select * from mails where isdeleted= + id; try { con.Open(); cmd = new SqlCommand(sql, con); dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { Receiver = dataReader[receiver].ToString(); Acceptor = dataReader[acceptor].ToString(); Subject = dataReader[subject].ToString(); Date = dataReader[date].ToString(); ListViewItem item = new ListViewItem(Receiver); LVMail.Items.Add(item); item.SubItems.AddRange(new string[] {Acceptor,Subject,Date}); } } catch(Exception ex) { MessageBox.Show(数据读取错误!, 错误提示, MessageBoxButtons.OK, MessageBoxIcon.Information); Console.Write(ex.Message); } finally { dataReader.Close(); con.Close(); } } }}程序运行后的错误提示是这个错误提示: a.form1.GetMail(int): 并非所有的代码都有返回值请问这是什么问题呢? 朋友们帮忙解答一下 谢谢了:)~  

你看这个定义:
public int GetMail(int id)
不是要有int类型的返回值么?
你却没写return语句,所以报了个错误。

如果你对using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace a{ public partial class Form1 : Form { SqlConnection con; SqlCommand cmd; SqlDataReader dataReader; public Form1() { InitializeComponent(); } private void toolStripButton2_Click(object sender, EventArgs e) { int id = Convert.ToInt32(((ToolStripButton)sender).Tag); //收件箱到tag是1,垃圾箱到tag是0 if (id == 1) { this.Text = GreenMail收件箱; } else if(id==0) { this.Text = GreenMail垃圾箱; } GetMail(id); //收件箱和垃圾箱共用tooStripButton2_click这一个方法,如果点击收件箱,把1传过去,如果点击垃圾箱,把0传过去, } private void toolStripButton4_Click(object sender, EventArgs e) { this.Close(); } private void Form1_Load(object sender, EventArgs e) { con = new SqlConnection(Data Source=.;Initial Catalog=GreenMail;Integrated Security=True); } public int GetMail(int id) { string Receiver=; string Acceptor=; string Subject=; string Date=; string sql = select * from mails where isdeleted= + id; try { con.Open(); cmd = new SqlCommand(sql, con); dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { Receiver = dataReader[receiver].ToString(); Acceptor = dataReader[acceptor].ToString(); Subject = dataReader[subject].ToString(); Date = dataReader[date].ToString(); ListViewItem item = new ListViewItem(Receiver); LVMail.Items.Add(item); item.SubItems.AddRange(new string[] {Acceptor,Subject,Date}); } } catch(Exception ex) { MessageBox.Show(数据读取错误!, 错误提示, MessageBoxButtons.OK, MessageBoxIcon.Information); Console.Write(ex.Message); } finally { dataReader.Close(); con.Close(); } } }}程序运行后的错误提示是这个错误提示: a.form1.GetMail(int): 并非所有的代码都有返回值请问这是什么问题呢? 朋友们帮忙解答一下 谢谢了:)~这个问题有好的意见或 建议,请留言
[] [返回上一页] [打 印]
电脑/网络评论 (评论内容只代表网友观点,与本站立场无关!)

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码

中原建材网 简单版 站长QQ:382546553