Click here to Skip to main content
15,888,968 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to implement Save As functionality in C# Pin
RajuPrasad8222-May-15 6:01
professionalRajuPrasad8222-May-15 6:01 
GeneralRe: How to implement Save As functionality in C# Pin
Sascha Lefèvre22-May-15 6:33
professionalSascha Lefèvre22-May-15 6:33 
AnswerRe: How to implement Save As functionality in C# Pin
CHill6022-May-15 8:14
mveCHill6022-May-15 8:14 
Questionobject reference not set to an instance of an object. Pin
abdo.kouta22-May-15 3:31
abdo.kouta22-May-15 3:31 
GeneralRe: object reference not set to an instance of an object. Pin
Sascha Lefèvre22-May-15 3:55
professionalSascha Lefèvre22-May-15 3:55 
GeneralRe: object reference not set to an instance of an object. Pin
abdo.kouta22-May-15 4:13
abdo.kouta22-May-15 4:13 
AnswerRe: object reference not set to an instance of an object. Pin
OriginalGriff22-May-15 4:26
mveOriginalGriff22-May-15 4:26 
GeneralRe: object reference not set to an instance of an object. Pin
Eddy Vluggen22-May-15 4:36
professionalEddy Vluggen22-May-15 4:36 
It points to a small part of your code;
C#
SqlCommand cmd =
    new SqlCommand(
        "insert into UsersData(id,UserName,Password) values('" + inid.Text + "','" +
        inUserName.Text + "','" + inPassword.Text + "')", con);
It is most likely that "inUserName" or "inPassword" controls are not found; hence, the exception. You should look into SQL injection; some idiot like me might otherwise wipe your entire database, instead of simply logging in. Stop concatenating strings - it is a cardinal sin. I'd also recommend to place the command in a using, to automatically dispose it, and to use the factory-method on the connection to create a command of the type of connection you are using:
C#
using(SqlCommand cmd = con.CreateCommand())
{
  // stuff using the command should go here, don't access it outside the block
  cmd.CommandText = "insert into UsersData(id,UserName,Password) values(@id,@username,@password)";
  cmd.Parameters.AddWithValue("id", 1);
  cmd.Parameters.AddWithValue("username", "johndoe");
  cmd.Parameters.AddWithValue("password", "No");
  if (1 != cmd.ExecuteNonQuery)
    System.Diagnostics.Debugger.Break(); // how did we insert more than 1 record?
}
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

SuggestionRe: object reference not set to an instance of an object. Pin
Richard Deeming22-May-15 5:08
mveRichard Deeming22-May-15 5:08 
GeneralRe: object reference not set to an instance of an object. Pin
Eddy Vluggen22-May-15 6:37
professionalEddy Vluggen22-May-15 6:37 
QuestionC# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 2:28
Member 1171127722-May-15 2:28 
AnswerRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 2:42
professionalSascha Lefèvre22-May-15 2:42 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 2:51
Member 1171127722-May-15 2:51 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 3:17
professionalSascha Lefèvre22-May-15 3:17 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 3:22
Member 1171127722-May-15 3:22 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 3:29
professionalSascha Lefèvre22-May-15 3:29 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 3:47
Member 1171127722-May-15 3:47 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 3:57
professionalSascha Lefèvre22-May-15 3:57 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 3:59
Member 1171127722-May-15 3:59 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 4:12
professionalSascha Lefèvre22-May-15 4:12 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 4:15
Member 1171127722-May-15 4:15 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 4:17
Member 1171127722-May-15 4:17 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 4:35
professionalSascha Lefèvre22-May-15 4:35 
Questionhow to keep datagridview in editmode on pressing of arrow keys Pin
Muhammad Waqas Aziz22-May-15 0:32
Muhammad Waqas Aziz22-May-15 0:32 
AnswerRe: how to keep datagridview in editmode on pressing of arrow keys Pin
Sascha Lefèvre22-May-15 1:00
professionalSascha Lefèvre22-May-15 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.