数据操作程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ADO
{
public partial class operation : Form
{
public operation()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
#region 显示总体分类
//确定数据库连接字符串
string constr = “server=Flz;database=product;Integrated Security=True;”;
//实例化数据库连接对象
SqlConnection conn = new SqlConnection(constr);
//打开数据库连接
conn.Open();
//实例化SqlCommand 对象(该对象主要用来执行SQL命令)
SqlCommand comm = new SqlCommand();
comm.CommandText = “select id,name from classify”;
comm.CommandType = CommandType.Text;
comm.Connection = conn;
//申明一个SqlDataReader(数据流)对象,并将comm执行后的结果交给他
SqlDataReader sdr = comm.ExecuteReader();
while (sdr.Read())
{
comboBox1.Items.Add(sdr[0]+“–>”+sdr[“name”]);
}
sdr.Close();
conn.Close();
#endregion
#region 左下角显示商品种类
using (SqlConnection conn2 = new SqlConnection(constr))
{
conn2.Open();
SqlCommand comm2 = new SqlCommand(“select count(*) from product”,conn2);
string sum = comm2.ExecuteScalar().ToString();
label2.Text = string.Format(“共计{0}种商品”,sum);
}
#endregion
}
#region 载入分类
private void button1_Click(object sender, EventArgs e)
{
string constr = “server=Flz;database=product;Integrated Security=True;”;
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand comm = new SqlCommand();
//获取分类id
int i = comboBox1.Text.IndexOf(“–>”);//获取字符串中“–>”所在位置索引
string id = comboBox1.Text.Substring(0,i);//只获取–>之前的字符
if (Convert.ToInt32(id)==0)
{
MessageBox.Show(“请先选择分类!”);
}
comm.CommandText = “select *from product where c_id=”+id;
comm.CommandType = CommandType.Text;
comm.Connection = conn;
SqlDataReader sdr = comm.ExecuteReader();
listBox1.Items.Clear();
while (sdr.Read())
{
listBox1.Items.Add( sdr[“id”]+“:”+sdr[“name”]);
}
sdr.Close();
conn.Close();
}
#endregion
#region 显示名称、价格、库存详细信息
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
button2.Text = “修改”;
string constr = “server=Flz;database=product;Integrated Security=True;”;
using (SqlConnection conn=new SqlConnection(constr))
{
int index = comboBox1.Text.IndexOf(“–>”);//获取字符串中“–>”所在位置索引
string id = comboBox1.Text.Substring(0, index);//只获取–>之前的字符
int index1 = listBox1.Text.IndexOf(“:”); //获取字符串中:所在位置索引
string id1 = listBox1.Text.Substring(0,index); //只获取:之前的字符
string sql = "select *from product where (c_id=’ " + id + “’ )and (id='” + id1+ “')”;
SqlCommand comm = new SqlCommand(sql,conn);
conn.Open();
SqlDataReader sdr = comm.ExecuteReader();
while (sdr.Read())
{
tb_name.Text = sdr[“name”].ToString();
tb_price.Text = sdr[“price”].ToString();
tb_number.Text = sdr[“number”].ToString();
}
sdr.Close();
}
}
#endregion
private void button2_Click(object sender, EventArgs e)
{
switch (((Button)sender).Text)
{
#region 添加商品
case “添加”:
string constr = “server=Flz;database=product;Integrated Security=True;”;
using (SqlConnection conn = new SqlConnection(constr))
{
int i = comboBox1.Text.IndexOf(“–>”);//获取字符串中“–>”所在位置索引
string index = comboBox1.Text.Substring(0, i);//只获取–>之前的字符
string sql1=“select max(id) from product where c_id = '”+index+“';”;
conn.Open();
SqlCommand comm1 = new SqlCommand(sql1, conn);
int idmax = Convert.ToInt32(comm1.ExecuteScalar()) + 1;
conn.Close();
if (int.Parse(index) > 0)
{
if (tb_name.Text == string.Empty) MessageBox.Show(“请输入商品名称”);
else if (tb_price.Text == string.Empty) MessageBox.Show(“请输入商品价格”);
else if (tb_number.Text == string.Empty) MessageBox.Show(“请输入商品库存”);
else
{
string sql = “insert into product(id,name,price,number,c_id) values('” + idmax + “‘,’” + tb_name.Text + “‘,’” + tb_price.Text + “‘,’” + tb_number.Text + “‘,’” + index + "') ";
SqlCommand comm = new SqlCommand(sql, conn);
conn.Open();
int j = comm.ExecuteNonQuery();
if (j > 0) MessageBox.Show(“成功添加” + j.ToString() + “种商品的数据!”);
else MessageBox.Show(“真尴尬,一行都没添加上!”);
}
}
else MessageBox.Show(“先选择一个分类再添加,OK ???”);
} break;
#endregion
#region 修改商品
case “修改”:
string constr1 = “server=Flz;database=product;Integrated Security=True;”;
using (SqlConnection conn = new SqlConnection(constr1))
{
int index = comboBox1.Text.IndexOf(“–>”);//获取字符串中“–>”所在位置索引
string c_id = comboBox1.Text.Substring(0, index);//只获取–>之前的字符
int index1 = listBox1.Text.IndexOf(“:”); //获取字符串中:所在位置索引
string id = listBox1.Text.Substring(0, index); //只获取:之前的字符 where id=" + id and c_id=" + c_id + "
string sql = “update product set name='” + tb_name.Text + “',price=” + tb_price.Text + “,number=” + tb_number.Text +" where (c_id=’ " + c_id + “’ )and (id='” + id+ “')” ;
SqlCommand comm = new SqlCommand(sql,conn);
conn.Open();
int i = comm.ExecuteNonQuery();
if (i>0) MessageBox.Show(“成功修改” + i.ToString() + “个商品的数据!”);
else MessageBox.Show(“真尴尬,一行都没修改好!”);
conn.Close();
}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
2021年Java中高级面试必备知识点总结
在这个部分总结了2019年到目前为止Java常见面试问题,取其面试核心编写成这份文档笔记,从中分析面试官的心理,摸清面试官的“套路”,可以说搞定90%以上的Java中高级面试没一点难度。
本节总结的内容涵盖了:消息队列、Redis缓存、分库分表、读写分离、设计高并发系统、分布式系统、高可用系统、SpringCloud微服务架构等一系列互联网主流高级技术的知识点。
目录:
(上述只是一个整体目录大纲,每个点里面都有如下所示的详细内容,从面试问题——分析面试官心理——剖析面试题——完美解答的一个过程)
部分内容:
对于每一个做技术的来说,学习是不能停止的,小编把2019年到目前为止Java的核心知识提炼出来了,无论你现在是处于什么阶段,如你所见,这份文档的内容无论是对于你找面试工作还是提升技术广度深度都是完美的。
不想被后浪淘汰的话,赶紧搞起来吧,高清完整版一共是888页,需要的话可以点赞+关注
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
[外链图片转存中…(img-mEUjaaKO-1713613636594)]
[外链图片转存中…(img-6dwD7D2S-1713613636594)]
[外链图片转存中…(img-nRJgOZsd-1713613636594)]
对于每一个做技术的来说,学习是不能停止的,小编把2019年到目前为止Java的核心知识提炼出来了,无论你现在是处于什么阶段,如你所见,这份文档的内容无论是对于你找面试工作还是提升技术广度深度都是完美的。
不想被后浪淘汰的话,赶紧搞起来吧,高清完整版一共是888页,需要的话可以点赞+关注
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!