这是我的代码,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;//数据库连接所需要的头文件 它提供了数据库访问和修改等方法
namespace 交通流量统计
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;//定义外部声明
int i = 0;
int n = 0;
int m = 0;
int b = 0;
int c = 0;
//给按钮添加一个Click事件的处理函数
public void btn_add_Click(object sender, EventArgs e)
{
i += 1;
textShow.Text = i.ToString();//输入数据
} public void btn_sub_Click(object sender, EventArgs e)
{
i -= 1;
textShow.Text = i.ToString();//修改数据
} public void button6_Click(object sender, EventArgs e)
{
n += 1;
textBox1.Text = n.ToString();
} public void button3_Click(object sender, EventArgs e)
{
n -= 1;
textBox1.Text = n.ToString();
} public void button7_Click(object sender, EventArgs e)
{
m += 1;
textBox2.Text = m.ToString();
} public void button2_Click(object sender, EventArgs e)
{
m -= 1;
textBox2.Text = m.ToString();
} public void button8_Click(object sender, EventArgs e)
{
b += 1;
textBox3.Text = b.ToString();
}
public void button4_Click(object sender, EventArgs e)
{
b -= 1;
textBox3.Text = b.ToString();
}
public void button9_Click(object sender, EventArgs e)
{
c += 1;
textBox4.Text = c.ToString();
} public void button5_Click(object sender, EventArgs e)
{
c -= 1;
textBox4.Text = c.ToString();
} public void button1_Click(object sender, EventArgs e)
{
string Sql = "Data Source=USER-20160117ZY;Initial Catalog=交通流量统计;User ID=姚正军;Password=168168;";//Data Source 是数据源;Initial Catalog是数据库的名称;User ID是登录数据的用户名;Pwd是登录数据库的密码
con = new SqlConnection(Sql);//创建数据库连接实例
string insertString = "INSERT INTO table_name VALUES(" + textShow.Text + " ," + textBox1.Text + ","+ textBox2.Text + "," + textBox3.Text + "," + textBox4.Text +")";//取TextBox里的值插入到数据库的表中
SqlCommand com = new SqlCommand(insertString, con);//表示要对 SQL Server 数据库执行存储过程
con.Open();//打开
if (com.ExecuteNonQuery() != 0)//com.ExecuteNonQuery()执行语句,并返回受影响行数
MessageBox.Show("保存成功!");
else
MessageBox.Show("保存失败!");
con.Close();//关闭
}
private void button10_Click_1(object sender, EventArgs e)
{
textShow.Text = 0.ToString();
textBox1.Text = 0.ToString();
textBox2.Text = 0.ToString();
textBox3.Text = 0.ToString();
textBox4.Text = 0.ToString();//清除数据
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;//数据库连接所需要的头文件 它提供了数据库访问和修改等方法
namespace 交通流量统计
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;//定义外部声明
int i = 0;
int n = 0;
int m = 0;
int b = 0;
int c = 0;
//给按钮添加一个Click事件的处理函数
public void btn_add_Click(object sender, EventArgs e)
{
i += 1;
textShow.Text = i.ToString();//输入数据
} public void btn_sub_Click(object sender, EventArgs e)
{
i -= 1;
textShow.Text = i.ToString();//修改数据
} public void button6_Click(object sender, EventArgs e)
{
n += 1;
textBox1.Text = n.ToString();
} public void button3_Click(object sender, EventArgs e)
{
n -= 1;
textBox1.Text = n.ToString();
} public void button7_Click(object sender, EventArgs e)
{
m += 1;
textBox2.Text = m.ToString();
} public void button2_Click(object sender, EventArgs e)
{
m -= 1;
textBox2.Text = m.ToString();
} public void button8_Click(object sender, EventArgs e)
{
b += 1;
textBox3.Text = b.ToString();
}
public void button4_Click(object sender, EventArgs e)
{
b -= 1;
textBox3.Text = b.ToString();
}
public void button9_Click(object sender, EventArgs e)
{
c += 1;
textBox4.Text = c.ToString();
} public void button5_Click(object sender, EventArgs e)
{
c -= 1;
textBox4.Text = c.ToString();
} public void button1_Click(object sender, EventArgs e)
{
string Sql = "Data Source=USER-20160117ZY;Initial Catalog=交通流量统计;User ID=姚正军;Password=168168;";//Data Source 是数据源;Initial Catalog是数据库的名称;User ID是登录数据的用户名;Pwd是登录数据库的密码
con = new SqlConnection(Sql);//创建数据库连接实例
string insertString = "INSERT INTO table_name VALUES(" + textShow.Text + " ," + textBox1.Text + ","+ textBox2.Text + "," + textBox3.Text + "," + textBox4.Text +")";//取TextBox里的值插入到数据库的表中
SqlCommand com = new SqlCommand(insertString, con);//表示要对 SQL Server 数据库执行存储过程
con.Open();//打开
if (com.ExecuteNonQuery() != 0)//com.ExecuteNonQuery()执行语句,并返回受影响行数
MessageBox.Show("保存成功!");
else
MessageBox.Show("保存失败!");
con.Close();//关闭
}
private void button10_Click_1(object sender, EventArgs e)
{
textShow.Text = 0.ToString();
textBox1.Text = 0.ToString();
textBox2.Text = 0.ToString();
textBox3.Text = 0.ToString();
textBox4.Text = 0.ToString();//清除数据
}
}
}
既然是远程,地址呢? string Sql = "Data Source=USER-20160117ZY;Initial Catalog=交通流量统计;User ID=姚正军;Password=168168;";//Data Source 是数据源;Initial Catalog是数据库的名称;User ID是登录数据的用户名;Pwd是登录数据库的密码