不支持给定路径的格式。

玉帝哥哥 2012-02-03 10:44:56
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace 多窗格数据修改窗体实例
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void DataBind(int currentPosition)
{
if (currentPosition == 0)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
button4.Enabled = true;
}
else
{
if (currentPosition == comboBox1.Items.Count - 1)
{
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = false;
button4.Enabled = false;
}
else
{
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
}
}
BindingContext[dataSet11, "学生信息表"].Position = currentPosition;
string exePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
string fileName = exePath + dataSet11.Tables["学生信息表"].Rows[currentPosition]["相片URL"].ToString();
FileInfo test = new FileInfo(fileName);
if (test.Exists)
{
Image image1 = Image.FromFile(fileName);
pictureBox1.Image = image1;
}
else
{
pictureBox1.Image = null;
}
}
private void Form1_Load(object sender, EventArgs e)
{
dataSet11.Clear();
int n = sqlDataAdapter1.Fill(dataSet11, "学生信息表");
comboBox1.SelectedIndex = 0;
DataBind(0);
button6.Text = "修改";
button5.Enabled = false;
button7.Enabled = false;
textBox9.ReadOnly = true;
textBox1.ReadOnly = true;
textBox2.ReadOnly = true;
textBox3.ReadOnly = true;
textBox4.ReadOnly = true;
textBox5.ReadOnly = true;
textBox6.ReadOnly = true;
textBox7.ReadOnly = true;
textBox8.ReadOnly = true;



}

private void button5_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "图片文件(*.jpg)|*.jpg|图片文件(*.bmp)|*.bmp|所有(*.*)|*.*";
DialogResult dlr = ofd.ShowDialog();
if (dlr == DialogResult.OK)
{
Image image1 = Image.FromFile(ofd.FileName);
textBox9.Text = ofd.FileName;
pictureBox1.Image = image1;
}

}

private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
DataBind(0);
}

private void button2_Click(object sender, EventArgs e)
{
int current = this.comboBox1.SelectedIndex - 1;
comboBox1.SelectedIndex = current;
DataBind(current);
}

private void button3_Click(object sender, EventArgs e)
{
int current = comboBox1.SelectedIndex + 1;
comboBox1.SelectedIndex = current;
DataBind(current);
}

private void button4_Click(object sender, EventArgs e)
{
int current = comboBox1.Items.Count - 1;
comboBox1.SelectedIndex = current;
DataBind(current);
}

private void button6_Click(object sender, EventArgs e)
{
if (button6.Text == "修改")
{
textBox1.Focus();
button6.Text = "取消";
button5.Enabled = true;
button7.Enabled = true;
textBox1.ReadOnly = false;
textBox2.ReadOnly = false;
textBox3.ReadOnly = false;
textBox4.ReadOnly = false;
textBox5.ReadOnly = false;
textBox6.ReadOnly = false;
textBox7.ReadOnly = false;
textBox8.ReadOnly = false;
panel1.Enabled = false;
}
else
{
int n = comboBox1.SelectedIndex;
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11, "学生信息表");
comboBox1.SelectedIndex = n;
BindingContext[dataSet11, "学生信息表"].Position = n;
DataBind(n);
button6.Text = "修改";
button5.Enabled = false;
button7.Enabled = false;
textBox1.ReadOnly = true;
textBox2.ReadOnly = true;
textBox3.ReadOnly = true;
textBox4.ReadOnly = true;
textBox5.ReadOnly = true;
textBox6.ReadOnly = true;
textBox7.ReadOnly = true;
textBox8.ReadOnly = true;
panel1.Enabled = true;
}
}

private void button8_Click(object sender, EventArgs e)
{
this.Close();
}

private void button7_Click(object sender, EventArgs e)
{
string number = comboBox1.Text;
string name = textBox1.Text;
string sex = textBox2.Text;
string Class = textBox3.Text;
string datatime = textBox4.Text;
string face = textBox5.Text;
string nation = textBox6.Text;
string place = textBox7.Text;
string study = textBox8.Text;
string exePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
string photoPath = textBox9.Text;
int n = exePath.Length;
int m = photoPath.Length;
if (m > n)
{
photoPath = photoPath.Substring(n, m - n);
}
SqlCommand myCommand = sqlConnection1.CreateCommand();
myCommand.CommandText = "Update 学生信息表 set 姓名=@xm,性别=@xb,班级=@bj,出生日期=@csrq,政治面貌=@zzmm,民族=@mz,籍贯=@jg,学习状况=@xxzk,相片URL=@xp where 学号='" + number + "'";
myCommand.Parameters.Add("@xm", SqlDbType.Char, 10, "姓名");
myCommand.Parameters.Add("@xb", SqlDbType.Char, 2, "性别");
myCommand.Parameters.Add("@bj", SqlDbType.Char, 10, "班级");
myCommand.Parameters.Add("@csrq", SqlDbType.DateTime, 8, "出生日期");
myCommand.Parameters.Add("@zzmm", SqlDbType.Char, 10, "政治面貌");
myCommand.Parameters.Add("@mz", SqlDbType.Char, 10, "民族");
myCommand.Parameters.Add("@jg", SqlDbType.Char, 20, "籍贯");
myCommand.Parameters.Add("@xxzk", SqlDbType.Char, 10, "学习状况");
myCommand.Parameters.Add("@xp", SqlDbType.Char, 30, "相片URL");
myCommand.Parameters["@xm"].Value = name;
myCommand.Parameters["@xb"].Value = sex;
myCommand.Parameters["@bj"].Value = Class;
myCommand.Parameters["@csrq"].Value = datatime;
myCommand.Parameters["@zzmm"].Value = face;
myCommand.Parameters["@mz"].Value = nation;
myCommand.Parameters["@jg"].Value = place;
myCommand.Parameters["@xxzk"].Value = study;
myCommand.Parameters["@xp"].Value = photoPath;
sqlConnection1.Open();
try
{
myCommand.ExecuteNonQuery();
MessageBox.Show("数据已更新", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception E)
{
MessageBox.Show("格式错误", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
sqlConnection1.Close();
n = comboBox1.SelectedIndex;
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11, "学生信息表");
comboBox1.SelectedIndex = n;
BindingContext[dataSet11, "学生信息表"].Position = n;
DataBind(n);
button6.Text = "修改";
panel1.Enabled = true;
button5.Enabled = false;
button7.Enabled = false;
textBox1.ReadOnly = true;
textBox2.ReadOnly = true;
textBox3.ReadOnly = true;
textBox4.ReadOnly = true;
textBox5.ReadOnly = true;
textBox6.ReadOnly = true;
textBox7.ReadOnly = true;
textBox8.ReadOnly = true;

}

}
}

一放图片就不好使,提示 不支持给定的路径的格式,数据库是SQL2005
...全文
132 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdmh 2012-02-03
  • 打赏
  • 举报
回复
photoPath什么内容,图片字段什么格式啊

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧