FileStream fs = new FileStream(@"C:\ConnectString.txt",FileMode.Open,FileAccess.Read,FileShare.None);
StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();
SqlConnection conn = new SqlConnection(conString);
为什么StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();有问题?
StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();
SqlConnection conn = new SqlConnection(conString);
为什么StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();有问题?
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FileStream fs = new FileStream(@"C:\ConnectString.txt", FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();
Console.WriteLine(conString);
}
}
}
奇怪,我这里没有问题啊,
C:\ConnectString.txt这个文件存在不?
StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();语法执行上没有问题.读C:\ConnectString.txt 中第一行,作为连接字符串,传给conString.
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;
using System.IO;
,真是奇怪了。
FileStream fs = new FileStream(@"C:\ConnectString.txt",FileMode.Open,FileAccess.Read,FileShare.None);
StreamReader sr = new StreamReader(fs);
conString = sr.ReadLine();
SqlConnection conn = new SqlConnection(conString);
这样就提示错误 1 类、结构或接口成员声明中的标记“=”无效
这句的问题。所以我奇怪。明明没问题啊
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
using System.Data.SqlClient;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FileStream fs = new FileStream(@"C:\ConnectString.txt", FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs);
string conString = sr.ReadLine();
Console.WriteLine(conString);
SqlConnection conn = new SqlConnection(conString); }
}
}
Data Source=ZXH-JWY;Initial Catalog=CEC710;Integrated Security=True
Press any key to continue . . .没问题啊
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;
using System.IO;
namespace Report
{
public partial class ReportForm : Form
{
string conString = string.Empty;
FileStream fs = new FileStream(@"C:\ConnectString.txt",FileMode.Open,FileAccess.Read,FileShare.None);
StreamReader sr = new StreamReader(fs);
conString = sr.ReadLine();
SqlConnection conn = new SqlConnection(conString);
DataSet1 myData = new DataSet1();
SqlDataAdapter da;
public ReportForm()
{
InitializeComponent();
}
private void showReport()
{
da = new SqlDataAdapter("SELECT * FROM ReportTab", conn);
da.Fill(myData, "ReportTab");
//创建报表
CrystalReport1 cr = new CrystalReport1();
//设置报表的数据源
cr.SetDataSource(myData);
//设置报表视图的报表源
crystalReportViewer1.ReportSource = cr;
}
private void ReportForm_Load(object sender, EventArgs e)
{
//
showReport();
}
}
}
string conString = string.Empty;
FileStream fs = new FileStream(@"C:\ConnectString.txt",FileMode.Open,FileAccess.Read,FileShare.None);
StreamReader sr = new StreamReader(fs);
conString = sr.ReadLine();
SqlConnection conn = new SqlConnection(conString);
DataSet1 myData = new DataSet1();
SqlDataAdapter da;这部分代码怎么在函数外面?
外面有定义可以,但是不能执行的代码a !