新手遇到问题,需要高手解答一下,在线等
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Lg
{
class DataBase
{
private string StrSQL;
private string StrCon = "Integrated Security=SSPI;database=LoginPassword;server=. ";
private SqlConnection SqlCon;
// private SqlCommandBuilder SqlCmdBld;
private DataSet ds; //警告1从未对字段“Lg.DataBase.ds”赋值,字段将一直保持其默认值 null
private SqlDataAdapter da;
public DataSet SelectDataBase(string tempStrSQL, string tempTableName)
{
this.StrSQL = tempStrSQL;
this.SqlCon = new SqlConnection(StrCon);
this.da = new SqlDataAdapter(this.StrSQL,this.StrCon);
this.ds.Clear();
this.da.Fill(ds,tempTableName);
return ds;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Lg
{
public partial class Form1 : Form
{
// public static bool blCanLogin = false;
public static string strUser = " ";
private DataSet ds = new DataSet();
private DataTable myTable;
private DataRow myRow;
private string sendStrSQL = "select * from LoginPwd ";// where Name= "+this.textBox1.Text();
public Form1()
{
InitializeComponent();
DataBase db = new DataBase();
string sendTableName = "LoginPwd ";
this.ds = db.SelectDataBase(sendStrSQL,sendTableName);
this.myTable = ds.Tables[0];
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < myTable.Rows.Count; i++)
{
this.myRow = myTable.Rows[i];
if (myRow[0].ToString().Trim() == this.textBox1.Text.ToString().Trim() && myRow[1].ToString().Trim() == this.textBox2.Text.ToString().Trim())
{
MessageBox.Show( "legal user ");
}
}
MessageBox.Show( "用户名或密码不正确 ");
return;
}
}
}
我写一个登录的界面,却出现这个问题 警告1从未对字段“Lg.DataBase.ds”赋值,字段将一直保持其默认值 null
请大家帮我改一下吧,第一次自己写程序,因为大家小刀,不要对程序做太大的变化
[解决办法]
private DataSet ds= new DataSet();