-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.cs
57 lines (31 loc) · 1.12 KB
/
try.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient; //引用MySql
namespace Csharp调用mysql
{
class Program
{
static void Main(string[] args)
{
string constructorString = "server=localhost;User Id=root;password=111111;Database=db1";
MySqlConnection myConnnect = new MySqlConnection(constructorString);
myConnnect.Open();
MySqlCommand myCmd = new MySqlCommand("insert into student(id,grade,srange) values('jjj',22,22)", myConnnect);
Console.WriteLine(myCmd.CommandText);
if (myCmd.ExecuteNonQuery() > 0)
{
Console.WriteLine("数据插入成功!");
}
//myCmd.CommandText = "insert into student(id,grade,srange) values('jjj4',22,22)";
//Console.WriteLine(myCmd.CommandText);
//if (myCmd.ExecuteNonQuery() > 0)
//{
// Console.WriteLine("数据插入成功!");
//}
myCmd.Dispose();
myConnnect.Close();
}
}
}