Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: barcode Pin
k36madman29-Sep-07 12:02
k36madman29-Sep-07 12:02 
GeneralRe: barcode Pin
martin_hughes29-Sep-07 12:31
martin_hughes29-Sep-07 12:31 
GeneralRe: barcode Pin
k36madman29-Sep-07 14:39
k36madman29-Sep-07 14:39 
GeneralRe: barcode Pin
GuyThiebaut30-Sep-07 8:25
professionalGuyThiebaut30-Sep-07 8:25 
GeneralRe: barcode Pin
k36madman30-Sep-07 10:43
k36madman30-Sep-07 10:43 
QuestionRadio Buttons Pin
picasso229-Sep-07 7:52
picasso229-Sep-07 7:52 
AnswerRe: Radio Buttons Pin
Lutosław29-Sep-07 8:59
Lutosław29-Sep-07 8:59 
QuestionObject reference not set to an instance of an object. Pin
anydie29-Sep-07 7:20
anydie29-Sep-07 7:20 
Whenever i am trying to execute a select statement in a ExecuteScalar() i get the exception from subject: Object reference not set to an instance of an object.

My script is:

public int InsertRecordSP(ref invOrdenes orden)
{
Database db = new Database();

try
{
//abro la coneccion y defino el Store Procedure a utilizar
db.open("insertOrder");

//Ingreso los parametros del Store Procedure
db.setParam("lastOrder", orden.getOrden());

//Ejecuto el Store Procedure
return db.executeScalar();
}
catch (DatabaseException de)
{
log.Error("DatabaseException: " + de.Message);
}
finally
{
db.close();
}
return 0;

}

public Database()
{
// set variables
this.host = ConfigurationSettings.AppSettings.Get("sql-host");
this.user = ConfigurationSettings.AppSettings.Get("sql-user");
this.password = ConfigurationSettings.AppSettings.Get("sql-password");
this.database = ConfigurationSettings.AppSettings.Get("sql-database");

// create the SqlConnection object
String source = "server=" + host + ";uid=" + user + ";pwd=" + password + ";database=" + database;
conn = new SqlConnection(source);
}

public void open(string sprocName)
{
try
{
conn.Open();
scmd = new SqlCommand(sprocName, conn);
}
catch (Exception e)
{
throw new DatabaseException(e.Message);
}
}

public int getParam(string paramName)
{
SqlParameter sqlParam = new SqlParameter();
sqlParam.ParameterName = "@" + paramName;
sqlParam.SqlDbType = SqlDbType.Int;
return (int) sqlParam.Value;
}
public int executeScalar()
{
try
{
return (int)scmd.ExecuteScalar();
}
catch (Exception e)
{
throw new DatabaseException(e.Message);
}
}

What i am doing wrong?



Regards, Diego.
AnswerRe: Object reference not set to an instance of an object. Pin
Luc Pattyn29-Sep-07 7:55
sitebuilderLuc Pattyn29-Sep-07 7:55 
AnswerRe: Object reference not set to an instance of an object. Pin
Guffa29-Sep-07 7:57
Guffa29-Sep-07 7:57 
QuestionxmlTextReader [modified] Pin
jon-8029-Sep-07 6:46
professionaljon-8029-Sep-07 6:46 
Questionimage DBNull Pin
TAREQ F ABUZUHRI29-Sep-07 6:19
TAREQ F ABUZUHRI29-Sep-07 6:19 
AnswerRe: image DBNull Pin
Christian Graus29-Sep-07 11:33
protectorChristian Graus29-Sep-07 11:33 
Question.NET arbitrary precision arithmetic library Pin
thepersonof29-Sep-07 5:55
thepersonof29-Sep-07 5:55 
AnswerRe: .NET arbitrary precision arithmetic library Pin
thepersonof29-Sep-07 8:01
thepersonof29-Sep-07 8:01 
GeneralRe: .NET arbitrary precision arithmetic library Pin
Luc Pattyn29-Sep-07 8:07
sitebuilderLuc Pattyn29-Sep-07 8:07 
QuestionRegarding regular expressions Pin
anu8129-Sep-07 0:22
anu8129-Sep-07 0:22 
AnswerRe: Regarding regular expressions Pin
S. Senthil Kumar29-Sep-07 6:43
S. Senthil Kumar29-Sep-07 6:43 
QuestionI need help really!!!! Pin
chanzeb28-Sep-07 23:49
chanzeb28-Sep-07 23:49 
AnswerRe: I need help really!!!! Pin
Guffa29-Sep-07 0:05
Guffa29-Sep-07 0:05 
GeneralRe: I need help really!!!! Pin
Christian Graus29-Sep-07 0:27
protectorChristian Graus29-Sep-07 0:27 
GeneralRe: I need help really!!!! Pin
chanzeb29-Sep-07 0:34
chanzeb29-Sep-07 0:34 
QuestionIcon resource causing compile error Pin
DaveyM6928-Sep-07 23:24
professionalDaveyM6928-Sep-07 23:24 
Question[Message Deleted] Pin
svincoll428-Sep-07 23:13
svincoll428-Sep-07 23:13 
AnswerRe: How to optimize this code ? Pin
Guffa28-Sep-07 23:35
Guffa28-Sep-07 23:35 

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.