Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace EnQApp
{
    public partial class LoGEnq : Form
    {
        public LoGEnq()
        {
            InitializeComponent();
        }

        private void Btn1_Click(object sender, EventArgs e)
        {
            String Usrname = UName.Text;
            SqlConnection cn = new SqlConnection(global::DataBaseTest.Propeties.Settings.Default.Database1ConnectionString);

            try {
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "SELECT * FROM Login WHERE Uname=@Usr;";
                cmd.Parameters.AddWithValue("@Usr",Usrname);

                cmd.ExecuteNonQuery();
                MessageBox.Show("Thank you");
            }
            catch (Exception ex) { }
            finally { }
        }


It will come this error?
The type or namespace name 'DataBaseTest' could not be found in the global namespace (are you missing an assembly reference?)

What i can do for solve this issue?
Posted
Updated 27-Nov-14 22:53pm
v3
Comments
Tomas Takac 28-Nov-14 4:54am    
The message is pretty clear I think. Do you reference DataBaseTest assembly in your project? Or perhaps you connection string can be retrieved from somewhere else than DataBaseTest.Propeties.Settings.Default.Database1ConnectionString?
Hemas Ilearn 28-Nov-14 5:00am    
Yes but what is the assembly name for databaseset?
George Jonsson 28-Nov-14 5:19am    
The namespace DataBaseTest probably is in the project from where you copied the code.
And have you added a settings variable called Database1ConnectionString in your project?
Tomas Takac 28-Nov-14 5:22am    
I'm maybe not clear enough. You are getting your connection string from DataBaseTest.Propeties.Settings.Default.Database1ConnectionString right? So where is the Settings class? Where is the namespace DataBaseTest? This is your code. You must know where this stuff is located. My guess is you just copy-pasted something from other project. Check settings in you project. Does it contain the connection string?
V. 28-Nov-14 8:23am    
If you're learning C# (I think you are) may I suggest to start from a good book instead of copy/pasting code? There are many things wrong with the code you're writing, even if you fix the bug you mention here. I'm not trying to be negative here, we all have to start somewhere, but a good basis is important if you want to become a good developer.

The error means it does not know what DataBaseTest is. So, you may need to add a reference to wherever the code for DataBaseTest is or include the classes so the compiler can find it.
 
Share this answer
 
Instead of SqlConnection(global::DataBaseTest.Propeties.Settings.Default.Database1ConnectionString);

change it to

SqlConnection(global::EnQApp.Propeties.Settings.Default.Database1ConnectionString);

It will work
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900