首先安装成功数据库,两种方法,1:免装版,2:安装版(自行百度)安装过程中会有root密码设置。
然后win+r
输入cmd回车启动命令行,用mysql
-uroot
-p
会让输入设置的密码输入回车即可连接
首先定义一个基本 *** 作类,处理数据库 *** 作部分:
class BaseOperate
{
#region 数据连接
/// <summary>
/// 数据连接
/// </summary>
/// <returns></returns>
public SqlConnection getcon()
{
string M_str_sqlcon = "Data Source=(你的计算机名);Initial Catalog=db_Crm;User id=sa;Password=(sqlserver登录密码);integrated security=true";
SqlConnection myCon = new SqlConnection(M_str_sqlcon);
return myCon;
}
#endregion
#region 执行语句
/// <summary>
/// 执行SQL 语句
/// </summary>
/// <param name="M_str_sqlstr"></param>
public void getcom(string M_str_sqlstr)
{
SqlConnection sqlcon = thisgetcon();
sqlconOpen();
SqlCommand sqlcom = new SqlCommand(M_str_sqlstr, sqlcon);
sqlcomExecuteNonQuery();
sqlcomDispose();
sqlconClose();
sqlconDispose();
}
#endregion
#region 返回SqlDataReader
/// <summary>
/// 返回SqlDataReader
/// </summary>
/// <param name="M_str_sqlstr">SQL语句</param>
/// <returns></returns>
public SqlDataReader getread(string M_str_sqlstr)
{
SqlConnection sqlcon = thisgetcon();
SqlCommand sqlcom = new SqlCommand(M_str_sqlstr, sqlcon);
sqlconOpen();
SqlDataReader sqlread = sqlcomExecuteReader(CommandBehaviorCloseConnection);
return sqlread;
}
#endregion
#region 返回DataSet数据集
/// <summary>
/// 返回DataSet
/// </summary>
/// <param name="M_str_sqlstr">SQL语句</param>
/// <param name="M_str_table">表名</param>
/// <returns></returns>
public DataSet getds(string M_str_sqlstr, string M_str_table)
{
SqlConnection sqlcon = thisgetcon();
SqlDataAdapter sqlda = new SqlDataAdapter(M_str_sqlstr, sqlcon);
DataSet myds = new DataSet();
sqldaFill(myds, M_str_table);
return myds;
}
#endregion
}
然后在
导入按钮的点击事件加入下面代码:
private void btnSave_Click(object sender, EventArgs e)
{
BaseOperate boperate = new BaseClassBaseOperate();
boperategetcom("insert into tb_User(UserID,UserName,UserPwd) "
+ "values('" + txtUserIDTextTrim() + "','" + txtUserNameTextTrim()
+ "','" + txtUserPwdTextTrim() + "')");
}
在登陆界面添加的代码:
private void btnLogin_Click(object sender, EventArgs e)
{
BaseOperate boperate = new BaseClassBaseOperate();
SqlDataReader sqlread = boperategetread("select UserName,UserPwd from tb_User where UserName='" + cboxUNameTextTrim() + "' and UserPwd='" + txtPwdTextTrim() + "'");
sqlreadRead();
if (sqlreadHasRows)
{
thisHide();
//添加让你要显示的界面显示的代码
}
else//否则登陆不成功,给出提示,并清空密码框和用户名框,光标定在用户名框内。
{
MessageBoxShow("用户名或密码错误!", "提示", MessageBoxButtonsOK, MessageBoxIconInformation);
txtPwdText = "";
cboxUNameText = "";
cboxUNameFocus();
}
sqlreadClose();
}
以上就是关于如何运行自己的mysql数据库全部的内容,包括:如何运行自己的mysql数据库、visual studio 2010 做windows窗体,怎样可以在软件运行时,客户输入信息导入进去SQL数据库里。、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)