本文介绍了sql查询将数据保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想保存Albeant的Sql查询语法,对于列(日期)和数据类型(日期和时间)表名称(persdat)
Sql query syntax I want to save Albeant, for the column (date) and the type of data (date and time) the table name (persdat)
推荐答案
static MySqlConnection connection;
public void Add(Test test)
{
openConnection();
string query = "INSERT INTO Math (dateTime,degree,testTime) VALUES('" + String.Format("{0:yyyy-M-d HH:mm:ss}", test.DateTime) + "','" + test.Degree + "','" + test.TestTime + "')";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
closeConnection();
}
private void openConnection()
{
try
{
connection = new MySqlConnection("SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + username + ";" + "PASSWORD=" + password + ";");
connection.Open();
Isconnected = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Isconnected = false;
}
}
private void closeConnection()
{
try
{
connection.Close();
Isconnected = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
MySql.Data.dll [ ^ ]
MySql.Data.dll[^]
这篇关于sql查询将数据保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!