小编Dur*_*rga的帖子

删除图片框中显示的文件

我正在从openfiledialoge中选择文件并将其显示在图片框中,当我点击delete按钮时,它在文本框中显示我正在异常The process cannot access the file because it is being used by another process. 我搜索了很多这个例外以便得到解决,但是当我尝试关闭时,我没有解决任何问题带有imagename的文件,它位于文本框中,即我在图片框中显示的文件; 使用IsFileLocked方法,这会关闭并删除特定目录路径的所有文件,但是如何删除picturebox中显示的唯一文件,我哪里出错了

     public partial class RemoveAds : Form
    {
        OpenFileDialog ofd = null;
        string path = @"C:\Users\Monika\Documents\Visual Studio 2010\Projects\OnlineExam\OnlineExam\Image\"; // this is the path that you are checking.

        public RemoveAds()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (System.IO.Directory.Exists(path))
            {
                 ofd = new OpenFileDialog();
                ofd.InitialDirectory = path;
                DialogResult dr = new DialogResult();
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Image …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

9
推荐指数
1
解决办法
7276
查看次数

获取ArgumentException =>无法创建字段的子列表问题

这是我的Datagridview分页代码,为什么我Child list for field Questions cannot be created.在这行代码中没有使用这个ArgumentException this.dataGridView1.DataSource = GetCurrentRecords(1, con);.我哪里出错了

public partial class ShowEngClgList : Form
    {
        OleDbConnection con = null;
        private OleDbCommand cmd1;
        private OleDbCommand cmd2;
        private OleDbDataAdapter adp1 = null;
        DataSet ds;

        private int PageSize = 10;
        private int CurrentPageIndex = 1;
        private int TotalPage = 0; 
        public ShowEngClgList()
        {
            InitializeComponent();
            try
            {
                con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
                con.Open();
            }
            catch (Exception err)
            {

            }
            cmd1 = new OleDbCommand("Select * from Questions order …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
3984
查看次数

更改特定键的Hashtable值

当用户点击确认并查看按钮respactive(键,值)对被存储在哈希表中时,当用户点击查看按钮而不是特定列表项时元素颜色为红色,我想要的是if(key,value)对是否被添加如果用户点击确认按钮,使用评论按钮比我想改变它的值,简而言之这个(键,值)对我存储(问题,答案)所以如果用户不确定答案而不是他点击评论,并且后来他应该能够改变它的答案并标记为确认,所以这个列表项元素颜色变为绿色,我该怎么做

 private void AddtoHashTabl(string key, string value)
            {
                if (hashtable.ContainsKey(key))
                {

                }
                else
                {
                    hashtable.Add(key, value);
                }
            }
    private void Confirm_Click(object sender, EventArgs e)
            {
                string Q = "";
                string A = "";
                listView1.Items[Convert.ToInt16(listView1.SelectedItems[0].SubItems[0].Text) - 1].BackColor = Color.Green;

                var q = Convert.ToInt16(listView1.SelectedItems[0].Text);
                var selectedQuestion = questions[q - 1];
                Q = selectedQuestion.Id;
                if (radioButton12.Checked == true)
                    A = "1";
                else if (radioButton11.Checked == true)
                    A = "2";
                if (radioButton10.Checked == true)
                    A = "3";
                if (radioButton9.Checked == true)
                    A = "4"; …
Run Code Online (Sandbox Code Playgroud)

.net c#

5
推荐指数
1
解决办法
3万
查看次数

错误:没有给出一个或多个必需参数的值

我试图通过dataetimepicker's month and year value与存储在类型的数据库列中的日期进行比较来获取Id Date/Time,下面是我正在使用的查询,但它显示我在此行中出现以下错误while (rs.Read())

错误

No value given for one or more required parameters.
Run Code Online (Sandbox Code Playgroud)

public int GetDrID_MonthWise(string DrName,int month,int year, int refDrID)
{
    int data = 0;
    try
    {
        string sql = "Select d.DoctorID From Doctor_Master d,Patient_registration p where d.LastName + ' ' + d.FirstName = '" + DrName + "' AND datepart(mm,p.[RegDate])=@month AND datepart(yyyy,p.[RegDate])=@year AND p.DoctorID=" + refDrID;
        cmd = new OleDbCommand(sql, acccon);
        cmd.Parameters.AddWithValue("@month", month);
        cmd.Parameters.AddWithValue("@year", year);
        rs = cmd.ExecuteReader();
        while …
Run Code Online (Sandbox Code Playgroud)

c# ms-access

5
推荐指数
1
解决办法
1万
查看次数

错误:在传递带有已修改行的DataRow集合时,Update需要有效的UpdateCommand

我正在使用Paging来显示数据datagridview,但是当我尝试使用updatebutton数据更新任何数据时,应该更新在datagridview数据库中以及数据库中.

但我得到这个错误:

在传递带有已修改行的DataRow集合时,Update需要有效的UpdateCommand

发生在这一行:

adp1.Update(dt);//here I am getting error
Run Code Online (Sandbox Code Playgroud)

下面是代码

public partial class EditMediClgList : Form
    {        
        public EditMediClgList()
        {
            InitializeComponent();
            try
            {
                con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb");
                con.Open();
            }
            catch (Exception err)
            {
                MessageBox.Show("Error:" +err);
            }

            cmd1 = new OleDbCommand("Select * from MedicalColeges order by MedicalClgID", con);
            ds = new DataSet();
            adp1 = new OleDbDataAdapter(cmd1);
            adp1.Fill(ds, "MedicalColeges");
            dataGridView1.DataSource = ds;

            // Get total count of the pages; 
            this.CalculateTotalPages();
            // Load the first page …
Run Code Online (Sandbox Code Playgroud)

.net c# ado.net dataadapter

4
推荐指数
1
解决办法
2万
查看次数

错误:不支持给定路径的格式

The given path's format is not supported.在此行获取此错误

System.IO.Directory.CreateDirectory(visit_Path);
Run Code Online (Sandbox Code Playgroud)

我在下面的代码中做错了

void Create_VisitDateFolder()
        {
            this.pid = Convert.ToInt32(db.GetPatientID(cmbPatientName.SelectedItem.ToString()));
            String strpath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            String path = strpath + "\\Patients\\Patient_" + pid + "\\";
            string visitdate = db.GetPatient_visitDate(pid);
            this.visitNo = db.GetPatientID_visitNo(pid);
            string visit_Path = path +"visit_" + visitNo + "_" + visitdate+"\\";
            bool IsVisitExist = System.IO.Directory.Exists(path);
            bool IsVisitPath=System.IO.Directory.Exists(visit_Path);
            if (!IsVisitExist)
            {
                System.IO.Directory.CreateDirectory(path);
            }
            if (!IsVisitPath)
            {
                System.IO.Directory.CreateDirectory(visit_Path);\\error here
            }
        }
Run Code Online (Sandbox Code Playgroud)

得到这个值 visit_Path

C:\Users\Monika\Documents\Visual Studio 2010\Projects\SonoRepo\SonoRepo\bin\Debug\Patients\Patient_16\visit_4_16-10-2013 00:00:00\
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
2
解决办法
4万
查看次数

正确设置MdiParent背景图像

我使用下面的代码来设置MdiParent表单的背景图像,它运行良好,但是当我点击最大化按钮时,BackgroundImage在右侧和底部边缘重复(即右侧和底侧图像部分重复),怎么做我避免这种情况并正确显示图像?

public Parent()
{
    InitializeComponent();

    foreach (Control ctl in this.Controls)
    {
        if (ctl is MdiClient)
        {
            ctl.BackgroundImage = Properties.Resources.bg;
            ctl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# winforms

2
推荐指数
1
解决办法
9744
查看次数

如何使数据网格视图列作为链接​​类型

我正在获取数据并存储在数据表中以在 datatgridview 中显示它,如何使数据表的第二列visitdate成为link type?像这样的东西

DataGridViewLinkColumn linkcol = new DataGridViewLinkColumn();
this.dataGridViewVisits.Columns[1].DefaultCellStyle = linkcol;
Run Code Online (Sandbox Code Playgroud)

下面是我在 datagridview 中显示数据的代码

cmd1 = new OleDbCommand("Select VisitNo,VisitDate,remark from Patient_Visit_Details WHERE Patient_ID=" + pid, con);
            dt = new DataTable();
            adp1 = new OleDbDataAdapter(cmd1);
            adp1.Fill(dt);
            this.dataGridViewVisits.DataSource = dt;
            DataGridViewLinkColumn linkcol = new DataGridViewLinkColumn();
Run Code Online (Sandbox Code Playgroud)

c# datagridview

1
推荐指数
1
解决办法
3798
查看次数

错误:非静态字段,方法或属性'Microsoft.Win32.RegistryKey.SetValue(string,object)'需要对象引用

得到此错误An object reference is required for the non-static field, method, or property 'Microsoft.Win32.RegistryKey.SetValue(string, object)',我已从Registry中获取值并尝试使用下面的代码使用新值更新它们,但它显示我这个错误,我出错了?

private void button2_Click(object sender, EventArgs e)
        {
            txtEmailID.Enabled = true;
            string eid = txtEmailID.Text;
            RegistryKey key = Registry.ClassesRoot;
            RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\StudentExam\Protection", true);
            RegistryKey.SetValue("EmailID", eid);//Error at this Line
         }
Run Code Online (Sandbox Code Playgroud)

.net c#

0
推荐指数
1
解决办法
220
查看次数

标签 统计

c# ×9

.net ×3

ado.net ×1

asp.net ×1

dataadapter ×1

datagridview ×1

ms-access ×1

winforms ×1