?
Solved

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

Posted on 2010-08-26
14
Medium Priority
?
1,116 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 59

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
Industry Leaders: 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 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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