Solved

Type or namespace definition, or end-of-file expected

Posted on 2010-08-26
14
1,095 Views
Last Modified: 2012-05-10
Why do I get the following error?
Error      2      Type or namespace definition, or end-of-file expected      C:\Users\Isaac S\Documents\Visual Studio 2008\WebSites\laraFabric\contact.aspx.cs      60      1      C:\...\laraFabric\


Also, am I connecting to mysql the right way?
using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using MySql.Data.MySqlClient;

using System.Data.SqlClient;



public partial class contact : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {



    }

    

    protected void image_Click(object sender, EventArgs e)

    {

        MySqlConnection connection = new MySqlConnection("Network Address=localhost;" +

                                                "Initial Catalog='fabrics';" +

                                                "Persist Security Info=no;" +

                                                "User Name='root';" +

                                                "Password='oap'");



                

                string cmdText = "INSERT INTO fabrics(name ,email ,message)";

                cmdText += "VALUES(?name ,?email ,?message);";



                MySqlCommand cmd = new MySqlCommand(cmdText, connection);



                cmd.CommandType = CommandType.Text;



                cmd.Parameters.Add("?name", MySqlDbType.VarChar).Value = 



                cmd.Parameters.Add("?email", MySqlDbType.VarChar).Value = 



                cmd.Parameters.Add("?message", MySqlDbType.VarChar).Value = 



                connection.Open();

            try

            {

         

                int result = cmd.ExecuteNonQuery();



                lblError.Text = "Data Saved";

            }

            catch (Exception ex)

            {

                lblError.Text = ex.Message;

            }

        }

    }

 }

}

Open in new window

0
Comment
Question by:Isaac
14 Comments
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33538590
Hi,

You have put extra ending braces in code so.

Check code.

Regards,
VSS

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;

public partial class contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    
    protected void image_Click(object sender, EventArgs e)
    {
        MySqlConnection connection = new MySqlConnection("Network Address=localhost;" +
                                                "Initial Catalog='fabrics';" +
                                                "Persist Security Info=no;" +
                                                "User Name='root';" +
                                                "Password='oap'");

                
                string cmdText = "INSERT INTO fabrics(name ,email ,message)";
                cmdText += "VALUES(?name ,?email ,?message);";

                MySqlCommand cmd = new MySqlCommand(cmdText, connection);

                cmd.CommandType = CommandType.Text;

                cmd.Parameters.Add("?name", MySqlDbType.VarChar).Value = 

                cmd.Parameters.Add("?email", MySqlDbType.VarChar).Value = 

                cmd.Parameters.Add("?message", MySqlDbType.VarChar).Value = 

                connection.Open();
            try
            {
         
                int result = cmd.ExecuteNonQuery();

                lblError.Text = "Data Saved";
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
      }
}

Open in new window

0
 
LVL 51

Expert Comment

by:HainKurt
ID: 33538595
is the code missing some parts?
you do have lots of extra } at the end, count { & }, they should be same...
also I dont see any namespace declaretion here
0
 
LVL 5

Author Comment

by:Isaac
ID: 33538622
Thanks vs00saini,

Now I get this error:
 Error      1      Cannot implicitly convert type 'void' to 'object'      C:\Users\Isaac S\Documents\Visual Studio 2008\WebSites\laraFabric\contact.aspx.cs      45      9      C:\...\laraFabric\

Also, I have a form with 3 fields (name, email and message) and intellisense is not picking it up.
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33538629
Hi,

Please tell me why these lines are not complete.

cmd.Parameters.Add("?name", MySqlDbType.VarChar).Value =                cmd.Parameters.Add("?email", MySqlDbType.VarChar).Value =                cmd.Parameters.Add("?message", MySqlDbType.VarChar).Value =

with no value set as parameter.

I think it can be also problem.

Regards,
VSS

0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33538652
Hi,

I have a form with 3 fields (name, email and message)  and intellisense is not picking it up.                            

Either your partial files are not matching. So let us know the other code too.

Regards,
VSS
0
 
LVL 5

Author Comment

by:Isaac
ID: 33538876

<%@ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="contact.aspx.cs" Inherits="contact" Title="Lara Fabrics - Contact" %>



<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<div id="center_content">

        

        <div class="title"><img src="images/contact_title.gif" alt="" title="" /></div>

        

		<div class="product_box">



        

		        <div id="contact_form">

                        <label class="contact_form">Name:</label>

		      			<input type="text" name="name" class="contact_input" id="name" />

		       			<div class="cleardiv"></div>

                        <label class="contact_form">Email:</label>

		      		 	<input type="text" name="email"  class="contact_input" id="email"/>

		       			<div class="cleardiv"></div>

                        <label class="contact_form">Message:</label>

		      		 	<textarea name="message" cols="" rows="" class="contact_textarea" id="message"></textarea>

		       			<div class="cleardiv"></div>

                        <input type="image" src="images/submit.gif" id="image" class="contact_submit" onclick="image_Click" />

                    

            

      		            <asp:Label ID="lblError" runat="server" Text="Label"></asp:Label>

                    

            

      		   </div>







        </div>

              

        



        

        

        </div>

</asp:Content>

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 33538977
Hi,

Modify your code as shown. (I have attach attribute runat="server" )

Regards,
VSS

<%@ Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="contact.aspx.cs" Inherits="contact" Title="Lara Fabrics - Contact" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="center_content">
        
        <div class="title"><img src="images/contact_title.gif" alt="" title="" /></div>
        
                <div class="product_box">

        
                        <div id="contact_form">
                        <label class="contact_form">Name:</label>
                                        <input type="text" name="name" class="contact_input" id="name" runat="server"  />
                                        <div class="cleardiv"></div>
                        <label class="contact_form">Email:</label>
                                        <input type="text" name="email"  class="contact_input" id="email" runat="server" />
                                        <div class="cleardiv"></div>
                        <label class="contact_form">Message:</label>
                                        <textarea name="message" cols="" rows="" class="contact_textarea" id="message" runat="server" ></textarea>
                                        <div class="cleardiv"></div>
                        <input type="image" src="images/submit.gif" id="image" class="contact_submit" onclick="image_Click" runat="server" />
                    
            
                            <asp:Label ID="lblError" runat="server" Text="Label"></asp:Label>
                    
            
                   </div>



        </div>
              
        

        
        
        </div>
</asp:Content>

Open in new window

0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33539133
Hi,

I forget to mention. After adding attributes. Build your project and then you can see intellisense working for all those controls in .cs file.

Regards,
VSS
0
 
LVL 5

Author Comment

by:Isaac
ID: 33540369
Vs00saini:

Thanks for all your help.
Unfortunately, when I tried to award you the points, I got the following error:
EmailTemplateTag replacement not found: TA_PATH (ID: 23)

I have notified the the Community Support Zone of the problem.
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33540396
Hi,

It seems something happening wrong with my  ID especially. Before it I answer to two questions correctly and same error reporting there too.

But I would say to you to allot points as soon you get resolution message from Community Support.

Thanks for notifying the same to Community Support.

Regards,
V.S.Saini
0
 
LVL 5

Author Comment

by:Isaac
ID: 33540440
As soon as they fix the problem, I'll allot the points.
Thanks again!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 33540698
Test comment

mbizup
EE Zone Advisor
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now