insert into select时如果select没有记录时的返回需要做dbnull.value判断

本文讨论了在使用SQL的INSERT INTO SELECT语句时,如果SELECT部分返回空结果集的情况。通常需要进行DBNull.Value检查来确保数据操作的正确性。了解如何在查询中适当地处理这种情况对于防止数据库异常至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
        * 函数名:executeInsert
        * 参数:sqln SQL语句[其中变量名需要@a1...@a2...@a3..以此类推]   parameter 对应的参数值,需要用splitc为分隔符
        * 执行SQL语句,执行插入语句,并返回插入的ID
        * 调用范例executeSQLN("insert into * from test000001 where id  = @a1 or id = @a2"  ,         "11" + splitc + "14"); * */
        public static int executeInsert(string SQLN, string parameter, int type)
        {
            SQLN += ";select @@identity;";
            SqlConnection objConnection = new SqlConnection(DAL.sqlhelper.connectionStr(type));
            if (objConnection.State != ConnectionState.Open)
            { objConnection.Open(); }
            SqlCommand objCommand = new SqlCommand();

            //new start

            objCommand.CommandText = SQLN;
            objCommand.Connection = objConnection;

            if (parameter.Length != 0)
            {
                string[] parameterArray = Regex.Split(parameter, splitc());//默认区分大小写
                int i1 = 0;

                foreach (string i in parameterArray)
                {
                    i1 = i1 + 1;
                    //objCommand.Parameters.Add("@a" + i1, SqlDbType.VarChar, 20).Value = i.ToString(); //需要指定数据类型
                    objCommand.Parameters.AddWithValue("@a" + i1, i.ToString());//不支持时间;
                }
            }
            //end
            int num = 0;
            if (! objCommand.ExecuteScalar().Equals(DBNull.Value))//当插入的语句是insert into select时,如果select没有记录,则需要做出判断,否则报错
                num = Convert.ToInt32(objCommand.ExecuteScalar());
            objConnection.Close();
            return num;
        }

 

using System; using System.Data; using System.Data.SQLite; using System.IO; namespace SqliteTimeFilter { internal class Program { private const string InputDb = @"input.db"; private const string OutputDb = @"output.db"; private static void Main() { if (File.Exists(OutputDb)) File.Delete(OutputDb); SQLiteConnection.CreateFile(OutputDb); using var srcConn = new SQLiteConnection($"Data Source={InputDb}"); using var dstConn = new SQLiteConnection($"Data Source={OutputDb}"); srcConn.Open(); dstConn.Open(); // 1. 仅创建 _3CH_12 表结构 const string getCreateSql = "SELECT sql FROM sqlite_master WHERE type='table' AND name='_3CH_12'"; string createTableSql; using (var cmdGet = new SQLiteCommand(getCreateSql, srcConn)) { createTableSql = cmdGet.ExecuteScalar() as string; } if (string.IsNullOrEmpty(createTableSql)) throw new Exception("源数据库里没有 _3CH_12 表!"); using (var cmdCreate = new SQLiteCommand(createTableSql, dstConn)) cmdCreate.ExecuteNonQuery(); // 2. 查询 18:30:50 – 18:10:00 之间的数据 const string sqlSelect = @" SELECT id, time, father, child, cycle, current_sys, master, data FROM _3CH_12 WHERE datetime(substr(replace(time, '\"', ''), 1, 19)) BETWEEN datetime('2025-07-12 17:30:00') AND datetime('2025-07-12 18:30:00'); "; using var cmdSelect = new SQLiteCommand(sqlSelect, srcConn); using var reader = cmdSelect.ExecuteReader(); // 3. 插入到新库 const string sqlInsert = "INSERT INTO `_3CH_12`(id, time, father, child, cycle, current_sys, master, data) " + "VALUES(@id, @time, @father, @child, @cycle, @current_sys, @master, @data)"; using var cmdInsert = new SQLiteCommand(sqlInsert, dstConn); cmdInsert.Parameters.Add("@id", DbType.Int64); cmdInsert.Parameters.Add("@time", DbType.String); cmdInsert.Parameters.Add("@father", DbType.String); cmdInsert.Parameters.Add("@child", DbType.String); cmdInsert.Parameters.Add("@cycle", DbType.String); cmdInsert.Parameters.Add("@current_sys", DbType.Int32); cmdInsert.Parameters.Add("@master", DbType.String); cmdInsert.Parameters.Add("@data", DbType.Binary); int count = 0; while (reader.Read()) { cmdInsert.Parameters["@id"].Value = reader["id"]; cmdInsert.Parameters["@time"].Value = reader["time"]; cmdInsert.Parameters["@father"].Value = reader["father"]; cmdInsert.Parameters["@child"].Value = reader["child"]; cmdInsert.Parameters["@cycle"].Value = reader["cycle"]; cmdInsert.Parameters["@current_sys"].Value = reader["current_sys"] == DBNull.Value ? DBNull.Value : reader["current_sys"]; cmdInsert.Parameters["@master"].Value = reader["master"]; cmdInsert.Parameters["@data"].Value = reader["data"]; cmdInsert.ExecuteNonQuery(); count++; } Console.WriteLine($"Finished. 共写入 {count} 条记录到 {OutputDb}"); } } }这是全部代码,怎么修改
最新发布
07-21
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _2 { public partial class KnowledgeTree : Form { private string connectionString = "Data Source=localhost;Initial Catalog=学习笔记管理;Integrated Security=True;"; // 声明控件变量 private SplitContainer mainSplitContainer; private TreeView treeView; private TextBox txtName1; private TextBox txtSubject1; private RichTextBox txtContent1; private int currentPointId = -1; // 跟踪当前编辑的知识点ID public KnowledgeTree() { InitializeComponent(); InitializeUI(); // 添加初始化调用 LoadKnowledgeTree(); // 添加树加载 } // 初始化界面控件 private void InitializeUI() { { // 主分割容器 mainSplitContainer = new SplitContainer { Dock = DockStyle.Fill, SplitterDistance = 300, Orientation = Orientation.Vertical // 明确分割方向 }; this.Controls.Add(mainSplitContainer); // 树视图 treeView = new TreeView { Dock = DockStyle.Fill, ImageList = CreateImageList(), ShowNodeToolTips = true }; mainSplitContainer.Panel1.Controls.Add(treeView); // 详情面板 Panel detailPanel = new Panel { Dock = DockStyle.Fill }; mainSplitContainer.Panel2.Controls.Add(detailPanel); // 详情控件 txtName = new TextBox { Location = new Point(10, 30), Width = 200 }; txtSubject = new TextBox { Location = new Point(10, 70), Width = 200 }; txtContent = new RichTextBox { Location = new Point(10, 110), Size = new Size(400, 200) }; btnSave = new Button { Text = "保存", Location = new Point(10, 320) }; btnSave.Click += SaveKnowledge; // 绑定保存事件 detailPanel.Controls.AddRange(new Control[] { new Label { Text = "名称", Location = new Point(10, 10) }, txtName1, new Label { Text = "学科", Location = new Point(10, 50) }, txtSubject, new Label { Text = "内容", Location = new Point(10, 90) }, txtContent1, btnSave }); } } private ImageList CreateImageList() { ImageList images = new ImageList(); images.ColorDepth = ColorDepth.Depth32Bit; images.ImageSize = new Size(24, 24); // 使用系统图标(实际应用中应使用自定义图标) images.Images.Add(SystemIcons.Information); // 0: 普通节点 images.Images.Add(SystemIcons.Warning); // 1: 重要节点 images.Images.Add(SystemIcons.Question); // 2: 问题节点 return images; } // 加载知识点树状图 private void LoadKnowledgeTree() { if (treeView == null) return; treeView.Nodes.Clear(); treeView.BeginUpdate(); try { // 获取所有知识点 DataTable points = GetKnowledgePoints(); // 创建节点字典 var nodeDict = new Dictionary<int, TreeNode>(); // 第一遍:创建所有节点 foreach (DataRow row in points.Rows) { int pid = Convert.ToInt32(row["Pid"]); string nodeText = $"{row["Pname"]} ({row["Stype"]})"; TreeNode node = new TreeNode(nodeText) { Name = pid.ToString(), Tag = row, // 存储整行数据 ToolTipText = row["Content"].ToString(), ImageIndex = GetNodeIconIndex(row["Stype"].ToString()) }; nodeDict.Add(pid, node); } // 第二遍:建立父子关系 foreach (DataRow row in points.Rows) { int pid = Convert.ToInt32(row["Pid"]); object parentObj = row["ParentId"]; if (parentObj != DBNull.Value) { int parentId = Convert.ToInt32(parentObj); if (nodeDict.ContainsKey(parentId)) nodeDict[parentId].Nodes.Add(nodeDict[pid]); } else { treeView.Nodes.Add(nodeDict[pid]); } } // 展开所有节点 treeView.ExpandAll(); // 添加节点选择事件 treeView.AfterSelect += (s, e) => DisplayPointDetails(e.Node); } catch (Exception ex) { MessageBox.Show($"加载树失败: {ex.Message}"); } finally { treeView.EndUpdate(); } } private int GetNodeIconIndex(string v) { // 简单示例:根据学科类型返回不同图标 return stype switch { "数学" => 0, "物理" => 1, "化学" => 2, _ => 0 }; } // 从数据库获取知识点 private DataTable GetKnowledgePoints() { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); // 确保关系表存在 EnsureRelationsTableExists(conn); // 修复表名引用:Point -> PointNote string sql = @"SELECT p.Pid, p.Pname, p.Stype, p.Content, r.ParentId FROM PointNote p LEFT JOIN Relations r ON p.Pid = r.ChildId"; using (var da = new SqlDataAdapter(sql, conn)) { var dt = new DataTable(); da.Fill(dt); return dt; } } } private void EnsureRelationsTableExists(SqlConnection conn) { // 修复表名引用:pointnote -> PointNote string sql = @" IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Relations') BEGIN CREATE TABLE Relations ( RelationId INT PRIMARY KEY IDENTITY, ParentId INT NULL, ChildId INT NOT NULL, CONSTRAINT FK_Child_Point FOREIGN KEY (ChildId) REFERENCES PointNote(Pid) ) END"; using (var cmd = new SqlCommand(sql, conn)) { cmd.ExecuteNonQuery(); } } private void label1_Click(object sender, EventArgs e) { } // 显示选中知识点的详情 private void DisplayPointDetails(TreeNode node) { if (node?.Tag == null) return; DataRow row = (DataRow)node.Tag; txtName.Text = row["Pname"].ToString(); txtSubject.Text = row["Stype"].ToString(); txtContent.Text = row["Content"].ToString(); currentPointId = Convert.ToInt32(row["Pid"]); // 设置当前编辑的ID } private void SaveKnowledge(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("知识点名称不能为空"); return; } using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); // 修复1: 插入到正确的表 PointNote // 修复2: 支持更新已有知识点 string sql = currentPointId == -1 ? @"INSERT INTO PointNote (Pname, Stype, Content) VALUES (@name, @subject, @content); SELECT SCOPE_IDENTITY();" : @"UPDATE PointNote SET Pname = @name, Stype = @subject, Content = @content WHERE Pid = @id; SELECT @id;"; using (var cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@name", txtName.Text); cmd.Parameters.AddWithValue("@subject", txtSubject.Text); cmd.Parameters.AddWithValue("@content", txtContent.Text); if (currentPointId != -1) cmd.Parameters.AddWithValue("@id", currentPointId); try { int newId = Convert.ToInt32(cmd.ExecuteScalar()); MessageBox.Show($"保存成功! ID: {newId}"); LoadKnowledgeTree(); // 刷新树 currentPointId = newId; // 更新当前ID } catch (Exception ex) { MessageBox.Show($"保存失败: {ex.Message}"); } } } } } 报错一堆怎么改
07-05
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; namespace WindowsFormsApp1 { public partial class Form1 : Form { private SQLiteConnection connection; private const string dbFile = "knowledge.db"; public Form1() { InitializeComponent(); InitializeDatabase(); LoadSubjects(); } // 初始化数据库 private void InitializeDatabase() { if (!File.Exists(dbFile)) { SQLiteConnection.CreateFile(dbFile); } connection = new SQLiteConnection($"Data Source={dbFile};Version=3;"); connection.Open(); // 创建学科表 string subjectSql = @"CREATE TABLE IF NOT EXISTS Subjects ( Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL UNIQUE)"; // 创建知识点表 string knowledgeSql = @"CREATE TABLE IF NOT EXISTS KnowledgePoints ( Id INTEGER PRIMARY KEY AUTOINCREMENT, SubjectId INTEGER NOT NULL, Title TEXT NOT NULL, Description TEXT, Image BLOB, FOREIGN KEY(SubjectId) REFERENCES Subjects(Id))"; ExecuteNonQuery(subjectSql); ExecuteNonQuery(knowledgeSql); } private void ExecuteNonQuery(string sql) { using (var cmd = new SQLiteCommand(sql, connection)) { cmd.ExecuteNonQuery(); } } // 加载所有学科 private void LoadSubjects() { cmbSubjects.Items.Clear(); string sql = "SELECT Id, Name FROM Subjects"; using (var cmd = new SQLiteCommand(sql, connection)) using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { cmbSubjects.Items.Add(new Subject( reader.GetInt32(0), reader.GetString(1) )); } } } private void 添加新学科ToolStripMenuItem_Click(object sender, EventArgs e) { string subjectName = txtNewSubject.Text.Trim(); if (string.IsNullOrEmpty(subjectName)) { MessageBox.Show("请输入学科名称"); return; } string sql = "INSERT INTO Subjects (Name) VALUES (@name)"; using (var cmd = new SQLiteCommand(sql, connection)) { cmd.Parameters.AddWithValue("@name", subjectName); cmd.ExecuteNonQuery(); } txtNewSubject.Clear(); LoadSubjects(); MessageBox.Show("学科添加成功!"); } private void 添加知识点ToolStripMenuItem_Click(object sender, EventArgs e) { if (cmbSubjects.SelectedItem == null) { MessageBox.Show("请先选择学科"); return; } var subject = (Subject)cmbSubjects.SelectedItem; string title = txtTitle.Text.Trim(); string description = txtDescription.Text; if (string.IsNullOrEmpty(title)) { MessageBox.Show("请输入知识点标题"); return; } // 处理图片 byte[] imageBytes = null; if (picImage.Image != null) { using (var ms = new MemoryStream()) { picImage.Image.Save(ms, picImage.Image.RawFormat); imageBytes = ms.ToArray(); } } // 插入数据库 string sql = @"INSERT INTO KnowledgePoints (SubjectId, Title, Description, Image) VALUES (@subjectId, @title, @desc, @image)"; using (var cmd = new SQLiteCommand(sql, connection)) { cmd.Parameters.AddWithValue("@subjectId", subject.Id); cmd.Parameters.AddWithValue("@title", title); cmd.Parameters.AddWithValue("@desc", description); cmd.Parameters.AddWithValue("@image", imageBytes ?? (object)DBNull.Value); cmd.ExecuteNonQuery(); } ClearKnowledgeForm(); MessageBox.Show("知识点添加成功!"); } private void 上传图片ToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp"; if (dlg.ShowDialog() == DialogResult.OK) { picImage.Image = new Bitmap(dlg.FileName); } } } private void ClearKnowledgeForm() { txtTitle.Clear(); txtDescription.Clear(); picImage.Image = null; } private void 查看知识点ToolStripMenuItem_Click(object sender, EventArgs e) { var viewForm = new KnowledgeViewer(connection); viewForm.ShowDialog(); } } public class Subject { public int Id { get; } public string Name { get; } public Subject(int id, string name) { Id = id; Name = name; } public override string ToString() => Name; } }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; namespace KnowledgeViewer { public partial class Form1 : Form { private TreeView treeView; private WebBrowser browser; private SQLiteConnection connection; public KnowledgeViewer(SQLiteConnection conn) { connection = conn; InitializeUI(); LoadData(); } private void InitializeUI() { this.Size = new Size(800, 600); this.Text = "知识点浏览器"; SplitContainer split = new SplitContainer(); split.Dock = DockStyle.Fill; split.SplitterDistance = 200; treeView = new TreeView(); treeView.Dock = DockStyle.Fill; treeView.AfterSelect += TreeView_AfterSelect; browser = new WebBrowser(); browser.Dock = DockStyle.Fill; split.Panel1.Controls.Add(treeView); split.Panel2.Controls.Add(browser); this.Controls.Add(split); } private void LoadData() { // 加载学科 string subjectSql = "SELECT Id, Name FROM Subjects"; using (var cmd = new SQLiteCommand(subjectSql, connection)) using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var subjectNode = new TreeNode(reader.GetString(1)) { Tag = $"Subject_{reader.GetInt32(0)}" }; treeView.Nodes.Add(subjectNode); LoadKnowledgePoints(subjectNode, reader.GetInt32(0)); } } } private void LoadKnowledgePoints(TreeNode parentNode, int subjectId) { string sql = "SELECT Id, Title FROM KnowledgePoints WHERE SubjectId = @subjectId"; using (var cmd = new SQLiteCommand(sql, connection)) { cmd.Parameters.AddWithValue("@subjectId", subjectId); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var pointNode = new TreeNode(reader.GetString(1)) { Tag = $"Point_{reader.GetInt32(0)}" }; parentNode.Nodes.Add(pointNode); } } } } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Tag == null) return; var parts = e.Node.Tag.ToString().Split('_'); if (parts[0] == "Point") { int pointId = int.Parse(parts[1]); DisplayKnowledgePoint(pointId); } } private void DisplayKnowledgePoint(int pointId) { string sql = "SELECT Title, Description, Image FROM KnowledgePoints WHERE Id = @id"; using (var cmd = new SQLiteCommand(sql, connection)) { cmd.Parameters.AddWithValue("@id", pointId); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { string title = reader.GetString(0); string description = reader.GetString(1); byte[] imageBytes = reader.IsDBNull(2) ? null : (byte[])reader[2]; string html = $"<h1>{title}</h1><p>{description.Replace("\n", "<br>")}</p>"; if (imageBytes != null) { string base64 = Convert.ToBase64String(imageBytes); html += $"<img src='data:image/png;base64,{base64}' style='max-width:100%'/>"; } browser.DocumentText = html; } } } } } 怎么改
07-03
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _2 { public partial class Addnotepoint : Form { // 声明 _imageData 字段 private byte[] _imageData = null; public Addnotepoint() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void Addnotepoint_Load(object sender, EventArgs e) { } private void textBox4_TextChanged(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void pcbtn_Click(object sender, EventArgs e) { this.Close(); } private void pabtn_Click(object sender, EventArgs e) { //如果文本框内容为空,返回 if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox4.Text.Trim() == "" || richTextBox1.Text.Trim() == "" || dateTimePicker1.Text == "") { MessageBox.Show("有空项", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 在插入前添加输入验证 if (string.IsNullOrWhiteSpace(textBox1.Text) || !int.TryParse(textBox1.Text, out _)) { MessageBox.Show("PID必须为有效整数"); return; } if (string.IsNullOrWhiteSpace(textBox2.Text)) { MessageBox.Show("Pname不能为空"); return; } if (dateTimePicker1.Value > DateTime.Now) { MessageBox.Show("保存日期不能是未来间"); return; } // 添加图片大小验证 if (_imageData != null && _imageData.Length > 2 * 1024 * 1024) { MessageBox.Show("图片大小不能超过 2MB"); return; } Dao3 dao = new Dao3(); dao.Connect(); // 确保连接已打开 // 使用参数化查询并指定实际字段名 string sql = @" INSERT INTO T_Point (Pid, Pname, Stype, [Content], Savedate, Image) VALUES (@Pid, @Pname, @Stype, @Content, @Savedate, @Image)"; // 创建参数列表,使用实际字段名作为参数名 List<SqlParameter> parameters = new List<SqlParameter> { // Pid - 假设是整数类型 new SqlParameter("@Pid", SqlDbType.Int) { Value = int.Parse(textBox1.Text) }, // Pname - 文本类型 new SqlParameter("@Pname", SqlDbType.NVarChar) { Value = textBox2.Text }, // Stype - 文本类型 new SqlParameter("@Stype", SqlDbType.NVarChar) { Value = textBox4.Text }, // [Content] - 注意Content是SQL关键字,需要用方括号包裹 new SqlParameter("@Content", SqlDbType.NVarChar) { Value = richTextBox1.Text }, // Savedate - 日期类型 new SqlParameter("@Savedate", SqlDbType.DateTime) { Value = dateTimePicker1.Value }, // 添加图片参数 new SqlParameter("@Image", SqlDbType.VarBinary) { Value = _imageData ?? (object)DBNull.Value } }; // 执行SQL命令 int n = dao.ExecuteParameterized(sql, parameters); if (n > 0) { MessageBox.Show("添加成功"); this.Close(); // 添加这行代码关闭窗口 } else { MessageBox.Show("添加失败"); } } private void textBox2_TextChanged(object sender, EventArgs e) { } private void btnSelectImage_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp"; openFileDialog.Title = "选择图片"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; try { // 检查文件是否存在 if (!File.Exists(filePath)) { MessageBox.Show($"文件不存在: {filePath}"); return; } // 检查文件大小限制(例如 2MB) FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.Length > 2 * 1024 * 1024) // 2MB { MessageBox.Show("图片大小不能超过 2MB"); return; } // 读取图片文件为字节数组 _imageData = File.ReadAllBytes(filePath); // 在PictureBox中显示图片 - 使用内存流避免文件锁定 using (MemoryStream ms = new MemoryStream(_imageData)) { pictureBox1.Image = Image.FromStream(ms); } lblImageStatus.Text = $"已选择图片 ({fileInfo.Length / 1024} KB)"; } catch (FileNotFoundException ex) { MessageBox.Show($"文件不存在: {ex.FileName}"); _imageData = null; } catch (PathTooLongException) { MessageBox.Show("文件路径过长,请将文件移动到较短的路径下"); _imageData = null; } catch (UnauthorizedAccessException) { MessageBox.Show("没有权限访问该文件"); _imageData = null; } catch (IOException ex) { MessageBox.Show($"文件读取错误: {ex.Message}"); _imageData = null; } catch (Exception ex) { MessageBox.Show($"加载图片失败: {ex.Message}"); _imageData = null; } finally { // 如果读取失败,清除图片预览 if (_imageData == null) { pictureBox1.Image = null; lblImageStatus.Text = "未选择图片"; } } } } } private void lblImageStatus_Click(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } } } 如何实现知识点与用户名称相对应
07-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值