Solved

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

Posted on 2010-08-26
14
1,102 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# LINQ ForEach() question 6 54
bound data table problem 2 33
ASP.NET (VB) return a record 2 38
.NET Enums [Flags] & Bitwise Design Question 6 29
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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