sql查询将数据保存在数据库中

编程入门 行业动态 更新时间:2024-10-27 12:24:46
本文介绍了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_insert.asp [ ^ ] 使用C#读取,插入,更新和删除简单的ADO.NET数据库. [ ^ ] :) It might be helpful, Sql_insert.asp[^] Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^] :)

阅读本文, SQL注入攻击以及有关如何进行注入的提示防止它们 [尤其是防止 ^ ]参数化查询部分.它将帮助您解决问题,并使您正确地开始. Read this article, SQL Injection Attacks and Some Tips on How to Prevent Them[^], especially the part on parameterised queries. It will help with your problem and get you started on the right track.

更多推荐

sql查询将数据保存在数据库中

本文发布于:2023-07-22 12:37:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   数据   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!