/// <summary>
        /// 导入到SQL
/// </summary>
public class DataBase
{
private static SqlConnection conn=null;
public DataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
} /**
 * 类的属性
 */
public static SqlConnection Connection
{
get
{
return conn;
}
} /**
 * 获取数据库连接,不返回值,通过属性来获取其值
 */
public static void GetConnection()
{
            string fileName = Application.StartupPath + "\\a.txt";
if(!File.Exists(fileName))
return;
string connStr="";
try
{
StreamReader reader=new StreamReader  (fileName,System.Text.Encoding.Default);
connStr=reader.ReadLine();
reader.Close();
}
catch
{
}
SqlConnection myconn=new SqlConnection(connStr);
try
{
myconn.Open();

}
catch(Exception err)
{
                MessageBox.Show(err.ToString(), "WindowsApplication2", MessageBoxButtons.OK, MessageBoxIcon.Error);
myconn=null;
}
conn=myconn;
} }
}
这个地方要一个循环 把文件内容读完 用while循环好些,判断读到了文件末尾,然后再加个:返回一个SqlConnectionStreamReader reader=new StreamReader(fileName,System.Text.Encoding.Default);
connStr=reader.ReadLine();
reader.Close();

解决方案 »

  1.   

    StreamReader reader=new StreamReader  (fileName,System.Text.Encoding.Default); 
    connStr=reader.ReadLine(); 
    reader.Close(); 
    ==
    StreamReader reader=new StreamReader  (fileName,System.Text.Encoding.Default); 
    connStr=reader.ReadLine(); 
    while(!string.IsNullOrEmpty(connStr))
    {
    //做处理
    connStr=reader.ReadLine();
    }
    reader.Close(); 
      

  2.   

    StreamReader reader=new StreamReader  (fileName,System.Text.Encoding.Default); 
    connStr=reader.ReadLine(); 
    while(!string.IsNullOrEmpty(connStr)) 

    //做处理 
    connStr=reader.ReadLine(); //照楼主意思应该connStr是不会随循环改变的吧,可能是放在第一行的

    reader.Close(); 
      

  3.   

    就是加一个WHILE循环,就可以了
      

  4.   

    2楼 amandag 说的应该很详细了... 
    如果LZ是这个意思的话..不是这个的话,请把你想问的说清楚些