I don't know what is your code ... the code above is fine ... but if you are using a class in the code ... let's say Employee .. then to create an object ... write code "Employee employee = new Employee()" ....
Find an error from this code & tell me the Solution of it please bro :)
Code is ::
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Configuration;
namespace CSharp_ADO.NET_Employee { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
Aasalam O Alaikum..!!
ReplyDelete:- Javed Bhai maine is video se dekh ke same as it is code likha hai apne pass same to same...
But ek error deraha hai jab main button pe click kar raha hoon ("Object reference not set to an instance of an Object ")
Please help me!!!!
My Code is here :::
try
{
string ConnectionString = ConfigurationManager.ConnectionStrings["employeedb"].ConnectionString;
SqlConnection Connection = new SqlConnection(ConnectionString);
SqlCommand Command = new SqlCommand("AddNewRecord", Connection);
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add("@EmployeeId", SqlDbType.NVarChar, 8).Value = EmployeeIDTextBox.Text;
Command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = FirstNameTextBox.Text;
Command.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = LastNameTextBox.Text;
Command.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = EmailTextBox.Text;
Command.Parameters.Add("@Telephone", SqlDbType.NVarChar, 50).Value = TelephoneTextBox.Text;
Connection.Open();
Command.ExecuteNonQuery();
Connection.Close();
MessageBox.Show("New Employee is added successfully!!!");
}
catch(Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
The code seems to be fine. This code may not have problem with it. Check the code before it. You may have missed creating an object.
DeleteHow to create Object ???
DeletePlease give me solution..!!!
DeleteI don't know what is your code ... the code above is fine ... but if you are using a class in the code ... let's say Employee .. then to create an object ... write code "Employee employee = new Employee()" ....
DeleteThis is my full Code :::
ReplyDeleteFind an error from this code & tell me the Solution of it please bro :)
Code is ::
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
namespace CSharp_ADO.NET_Employee
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void AddNewEmployeeButton_Click(object sender, EventArgs e)
{
try
{
string ConnectionString = ConfigurationManager.ConnectionStrings["employeedb"].ConnectionString;
SqlConnection Connection = new SqlConnection(ConnectionString);
SqlCommand Command = new SqlCommand("AddNewRecord", Connection);
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add("@EmployeeId", SqlDbType.NVarChar, 8).Value = EmployeeIDTextBox.Text;
Command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = FirstNameTextBox.Text;
Command.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = LastNameTextBox.Text;
Command.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = EmailTextBox.Text;
Command.Parameters.Add("@Telephone", SqlDbType.NVarChar, 50).Value = TelephoneTextBox.Text;
Connection.Open();
Command.ExecuteNonQuery();
Connection.Close();
MessageBox.Show("New Employee is added successfully!!!");
}
catch(Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
}
I stop to watch more Tutorials of Database because i am stuck in this Tutorial..!!! Please make a solution ..
ReplyDeletethere is no problem in the code ... It looks alright ... Research online and you will find the solution ...
DeleteI researched alot ..!! But didn't get a Single SolutioN ...
ReplyDeleteSalam Dear,
ReplyDeletei get the error message after clicking on add new employee. "Error: Object reference not set to an instance of an object".
Please help me,