错误2期望的类,委托,枚举,接口或结构行27,30,33,37,24,51 [英] Error 2 expected class, delegate, enum, interface, or struct line 27, 30, 33, 37, 24, 51

查看:115
本文介绍了错误2期望的类,委托,枚举,接口或结构行27,30,33,37,24,51的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.Data.SqlClient;

namespace AddrApp
{
    public partial class Form1 : Form
    {
        SqlConnection con= new SqlConnection(@"Data Source=DESKTOP-5KNSK7E\SQLEXPRESS;Initial Catalog=church;Integrated Security=True");  
        SqlCommand cmd;  
        SqlDataAdapter adapt;  
        //ID variable used in Updating and Deleting Record  
        int ID = 0;  
        public Form1()  
        {  
            InitializeComponent();  
            DisplayData();  
        }
    }
    private void DisplayData()

    {
 	throw new NotImplementedException();
    }  

        private void btn_Insert_Click(object sender, EventArgs e)  
{
            if (txt_name.Text != "" && txt_address.Text != "" && txt_contact.Text != "" && txt_clergy.Text != "" && txt_cantor.Text != "" && txt_charges.Text != "" && txt_picture.Text != "")  
            {  
                cmd = new SqlCommand("insert into church(Name,Address,Contact,Clergy,Cantor,Charges,Picture) values(@Name,@Address,@Contact,@Clergy,@Cantor,@Charges,@Picture)", con);  
                con.Open();  
                cmd.Parameters.AddWithValue("@Name", txt_name.Text);  
                cmd.Parameters.AddWithValue("@Address", txt_address.Text);
                cmd.Parameters.AddWithValue("@Contact", txt_contact.Text);  
                cmd.Parameters.AddWithValue("@Clergy", txt_clergy.Text);
                cmd.Parameters.AddWithValue("@Cantor", txt_cantor.Text);
                cmd.Parameters.AddWithValue("@Charges", txt_charges.Text);  
                cmd.Parameters.AddWithValue("@Picture", txt_picture.Text); 
                cmd.ExecuteNonQuery();  
                con.Close();  
                MessageBox.Show("Record Inserted Successfully");  
                DisplayData();  
                ClearData();  
            }  
            else
            {  
                MessageBox.Show("Please Provide Details!");  
            }  
}
        //Display Data in DataGridView  
        private void DisplayData()  
        {  
            con.Open();  
            DataTable dt=new DataTable();  
            adapt=new SqlDataAdapter("select * from church",con);  
            adapt.Fill(dt);  
            dataGridView1.DataSource = dt;  
            con.Close();  
        }  
        //Clear Data  
        private void ClearData()  
        {  
            txt_name.Text = "";  
            txt_address.Text = "";
            txt_contact.Text = "";  
            txt_clergy.Text = ""; 
            txt_cantor.Text = "";  
            txt_charges.Text = ""; 
            txt_picture.Text = "";  
            ID = 0;  
        }  
        //dataGridView RowHeaderMouseClick Event  
        private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)  
        {  
            ID = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());  
            txt_name.Text = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();  
            txt_address.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
            txt_contact.Text = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();  
            txt_clergy.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();  
            txt_cantor.Text = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();  
            txt_charges.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();   
            txt_picture.Text = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();     
        }  
        //Update Record  
        private void btn_Update_Click(object sender, EventArgs e)  
        {  
            if (txt_name.Text != "" && txt_address.Text != "" && txt_contact.Text != "" && txt_clergy.Text != "" && txt_cantor.Text != "" && txt_charges.Text != "" && txt_picture.Text != "")  
            {  
                cmd = new SqlCommand("update church set Name=@Name,Address=@Address,Contact=@Contact,Clergy=@Clergy,Cantor=@Cantor,Charges=@Charges,Picture=@Picture where ID=@ID", con);  
                con.Open();  
                cmd.Parameters.AddWithValue("@ID", ID);  
                cmd.Parameters.AddWithValue("@Name", txt_Name.name);  
                cmd.Parameters.AddWithValue("@Address", txt_address.Text);
                cmd.Parameters.AddWithValue("@Contact", txt_contact.Text);  
                cmd.Parameters.AddWithValue("@Clergy", txt_clergy.Text);  
                cmd.Parameters.AddWithValue("@Cantor", txt_cantor.Text);
                cmd.Parameters.AddWithValue("@Charges", txt_charges.Text);  
                cmd.Parameters.AddWithValue("@Picture", txt_picture.Text); 
                cmd.ExecuteNonQuery();  
                MessageBox.Show("Record Updated Successfully");  
                con.Close();  
                DisplayData();  
                ClearData();  
            }  
            else  
            {  
                MessageBox.Show("Please Select Record to Update");  
            }  
        }  
        //Delete Record  
        private void btn_Delete_Click(object sender, EventArgs e)  
        {  
            if(ID!=0)  
            {  
                cmd = new SqlCommand("delete church where ID=@ID",con);  
                con.Open();  
                cmd.Parameters.AddWithValue("@ID",ID);  
                cmd.ExecuteNonQuery();  
                con.Close();  
                MessageBox.Show("Record Deleted Successfully!");  
                DisplayData();  
                ClearData();  
            }  
            else  
            {  
                MessageBox.Show("Please Select Record to Delete");  
            } 

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}





我尝试了什么:



帮助,我已经尝试了一切,似乎无法搞清楚!!!!!



错误5预期的课程,代表,枚举,界面或结构LINE:27,30,33,37



错误6类型或命名空间定义,或预期的文件结束LINE:24,51



What I have tried:

Help, I have tried everything, cant seem to figure it out!!!!!

Error 5 Expected class, delegate, enum, interface, or struct LINE: 27, 30, 33, 37

Error 6 Type or namespace definition, or end-of-file expected LINE: 24,51

推荐答案

如果你将缩进你的代码,看到问题是微不足道的......



但是所有行都从第0列开始,很难看到不匹配{}。



If you would indent your code, it would be trivial to see the problem...

But having all lines start at column 0, it is hard to see mismatching { }.

public Form1() 
 { 
 InitializeComponent(); 
 DisplayData(); 
 }
 }  // This would end the class !!!





顺便说一句,鉴于第一个错误是在第27行。不是很难找到实际的问题是就在之前。



此外,几乎每个认真的编辑器都可以查看匹配的大括号。你只需要将光标放在}上,编辑器就会突出显示相应的{。



当你遇到这样的问题时,另一个技巧就是注释掉部分代码像{和}之间的任何东西一样。然后逐步添加代码。



但是使用现代编辑器,您还可以重新格式化代码,并修复缩进,从而更容易找到问题。但是,上述注释技巧可能对内部编译器错误很有用。例如。



And by the way, given the fact that the first error is on line 27. It is not very hard to find that the actual problem is just before.

Also, almost every serious editor allows to view matching braces. You just have to put your cursor on } and the editor would highlight the corresponding {.

And another trick when you have such problem is to comment out part of the code like anything between class { and }. Then you add code progressively.

But with modern editor, you also have a command to reformat your code and it would fix indentation thus making it easier to find the problem. However, the above trick of commenting might be useful for internal compiler error for example.


这篇关于错误2期望的类,委托,枚举,接口或结构行27,30,33,37,24,51的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆