C#看看这段代码哪里出问题了
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
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 Form1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn = new SqlConnection();
conn.open();
SqlCommand co=new SqlCommand();
co.Connection=conn;
com="select timenian from jifeng ";
SqlDataReader data=conn.ExcuteReader();
if(data.Read())
{
textBox1.text=data["timenian"].Tostring;
}
co="select timeyue from jifeng";
SqlDataReader data =conn.ExcuteReader();
if (data.Read())
{
textBox2.text=data["timeyue"].Tostring;
data.Close();
conn.Close();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 fm = new Form2();
fm.Show();
}
}
} 展开
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 Form1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn = new SqlConnection();
conn.open();
SqlCommand co=new SqlCommand();
co.Connection=conn;
com="select timenian from jifeng ";
SqlDataReader data=conn.ExcuteReader();
if(data.Read())
{
textBox1.text=data["timenian"].Tostring;
}
co="select timeyue from jifeng";
SqlDataReader data =conn.ExcuteReader();
if (data.Read())
{
textBox2.text=data["timeyue"].Tostring;
data.Close();
conn.Close();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 fm = new Form2();
fm.Show();
}
}
} 展开
5个回答
展开全部
把上面一段替换成
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.Open();
try
{
SqlCommand co = new SqlCommand();
co.Connection = conn;
co.CommandText = "select timenian,timeyue from jifeng ";
SqlDataReader data = co.ExecuteReader();
if (data.Read())
{
textBox1.text=data["timenian"].Tostring;
textBox2.text=data["timeyue"].Tostring;
}
data.Close();
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
你上面有的是名字写错了,有的是地方放错了
展开全部
SqlDataReader data 这个data是二维的 吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没看出问题在哪。。。能说说是什么问题吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果有问题的话,vs显示的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果有问题,那就是语法问题
if (data.Read())
{
textBox2.text=data["timeyue"].Tostring;
}//这里少了个大括号
if (data.Read())
{
textBox2.text=data["timeyue"].Tostring;
}//这里少了个大括号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询