Solved

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

Posted on 2010-08-26
14
1,108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 53

Expert Comment

by:Huseyin KAHRAMAN
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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