问题描述
注册界面:用户信息数据库:注册界面代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespaceWindowsFormsApplication1{publicpartialclassForm2:Form{publicForm2(){InitializeComponent();}publicboolbbool;privatevoidtextBox1_TextChanged_1(objectsender,EventArgse){Form2aa=newForm2();stringUser,Pwd;stringcon="IntegratedSecurity=SSPI;Database=Infor.mdf;Server=.";SqlConnectionmycon=newSqlConnection(con);mycon.Open();stringcmd="select*from用户信息";SqlCommandcom=newSqlCommand();com.CommandText=cmd;//commandtext属性com.Connection=mycon;//connection属性com.ExecuteNonQuery();SqlDataReaderreader=com.ExecuteReader();while(reader.Read())//从数据库读取用户信息{User=reader["ID"].ToString();Pwd=reader["PSW"].ToString();if(textBox1.Text.Trim()==reader["ID"].ToString().Trim()){MessageBox.Show("用户存在");bbool=true;return;}elseif(textBox1.Text.Trim()!=reader["ID"].ToString().Trim()){MessageBox.Show("恭喜你,该用户名可以使用。");bbool=false;}}}privatevoidbutton1_Click_1(objectsender,EventArgse){if(bbool==false){stringconn="server=127.0.0.1;uid=sa;pwd=123456;database=Infor";SqlConnectionmyconn=newSqlConnection(conn);myconn.Open();stringmysql="insertinto用户信息(ID,PSW)values('"+textBox1.Text+"',"+"'"+textBox2.Text+"')";SqlCommandcom2=newSqlCommand();com2.CommandText=mysql;//commandtext属性com2.Connection=myconn;//connection属性com2.ExecuteNonQuery();myconn.Close();MessageBox.Show("注册成功!点击确定,返回登录界面。","提示");this.Close();}}privatevoidtextBox2_TextChanged(objectsender,EventArgse){}}}
不知道为什么还是还是无法打开数据库?调试时提示:新手一枚,求助!!!!
解决方案
解决方案二:
拜托了!!有人吗!
解决方案三:
stringcon=@"DataSource=.;database=Infor;Integratedsecurity=true";
连接字符串改成↑