C# ConnectionString 属性尚未初始化。
SqlConnectionsqlConnection1=newSqlConnection();stringsql="selectuserpwdfromdatapwdwhe...
SqlConnection sqlConnection1 = new SqlConnection();
string sql = "select userpwd from datapwd where id=''";
SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(sql, sqlConnection1);
DataSet dt1 = new DataSet();
sqlDataAdapter1.Fill(dt1, "datapwd");
string sq2 = textBox13.Text;
string sq3 = (string)dt1.Tables["datapwd"].Rows[0]["userpwd"];
if (sq2.Equals(sq3.Trim()) && textBox14.Text == textBox15.Text)
{
string sqlret = "update datapwd set userpwd='" + textBox14.Text + "' where userpwd='" + textBox13.Text + "'";
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.Open();
SqlCommand cd = new SqlCommand(sqlret, sqlConnection);
SqlDataReader sr = cd.ExecuteReader();
MessageBox.Show(" 密码已修改成功", "提醒");
}
sqlDataAdapter1.Fill(dt1, "datapwd"); -----ConnectionString 属性尚未初始化。出现 什么原因 展开
string sql = "select userpwd from datapwd where id=''";
SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(sql, sqlConnection1);
DataSet dt1 = new DataSet();
sqlDataAdapter1.Fill(dt1, "datapwd");
string sq2 = textBox13.Text;
string sq3 = (string)dt1.Tables["datapwd"].Rows[0]["userpwd"];
if (sq2.Equals(sq3.Trim()) && textBox14.Text == textBox15.Text)
{
string sqlret = "update datapwd set userpwd='" + textBox14.Text + "' where userpwd='" + textBox13.Text + "'";
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.Open();
SqlCommand cd = new SqlCommand(sqlret, sqlConnection);
SqlDataReader sr = cd.ExecuteReader();
MessageBox.Show(" 密码已修改成功", "提醒");
}
sqlDataAdapter1.Fill(dt1, "datapwd"); -----ConnectionString 属性尚未初始化。出现 什么原因 展开
3个回答
展开全部
你的数据库连接字符串没有写啊
string connectionString="server=服务器名;database=数据库名;integrated security=true;"
sqlConnection1.ConnectionString = connectionString;
string connectionString="server=服务器名;database=数据库名;integrated security=true;"
sqlConnection1.ConnectionString = connectionString;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string connstr="server=服务器名;database=数据库名;integrated security=true;";
SqlConnection sqlConnection1 = new SqlConnection(connstr);
你在创建数据库连接的时候没有连接数据库的字符串
而且你string sql = "select userpwd from datapwd where id=''";这个也不完整啊
可以写成string sql ="select userpwd from datapwd where id='''+变量+"'";
SqlConnection sqlConnection1 = new SqlConnection(connstr);
你在创建数据库连接的时候没有连接数据库的字符串
而且你string sql = "select userpwd from datapwd where id=''";这个也不完整啊
可以写成string sql ="select userpwd from datapwd where id='''+变量+"'";
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把sql 放到上面去 在把sql放到SqlConnection sqlConnection1 = new SqlConnection(sql);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询