Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

916 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