HI..
I have a database created and having a table inside it..
now when i am inserting a value in my table it doesnot work...
And please tell me how to see the error if occurs in the eclipse plug in . I am very new to blackberry.
now the snippet code for inserting the value is
Database d;
URI myUri = URI.create("file:///SDCard/Databases/SQLite_Guide/", "Mynewdatabase1.db");
d= DatabaseFactory.create(myUri);
d.close;
Statement s1=d.createStatement("INSERT INTO People(Name,Age)VALUES ('uttam',23)");
s1.prepare();
s1.execute();
s1.close();
d.close();
You're closing the data base before calling createStatement? That isn't going to work. Is this the actual code, because the first you're missing the parens on the first call: d.close;
Related
At one point using FromSqlRaw to call stored procedures worked for me. I did not change anything in the project but now calling any stored procedure using FromSqlRaw returns
The underlying reader doesn't have as many fields as expected
I removed the model from the project and performed a BUILD. Then added the model back with no luck. I reduced the model and stored procedure to return a single column, no luck.
I tried adding Microsoft.EntityFrameworkCore.Relational as a dependency, no luck. All my unit test that use FromSqlRaw to call a stored procedure return the same error and at one time they all worked.
I have received Windows updates but nothing I know about that would have affected EF Core. I have run through all internet problem solving I can find. I am starting to think I will need to use ADO as a work around but I do not want a work around when it worked for me at one point. Something changed on my machine but I am not sure what to cause this problem.
Here is my test method in case my code is messed up. It is very straight forward not much to mess up. I tried the "var" out of desperation.
[TestMethod]
public void WorkOrderBOMGridABS()
{
List<WorkOrderBOMGridABS> baseList = new List<WorkOrderBOMGridABS>();
using (WorkOrderDataContext context = new WorkOrderDataContext())
{
var param = new SqlParameter[] {
new SqlParameter() {
ParameterName = "#WorkOrderId",
SqlDbType = System.Data.SqlDbType.Int,
Direction = System.Data.ParameterDirection.Input,
Value = 38385
}
};
baseList = context.WorkOrderBOMGridABS.FromSqlRaw("[dbo].[WorkOrderBOMGridABS] #WorkOrderId", param).ToList();
//var results = context.WorkOrderBOMGridABS.FromSqlRaw("[dbo].[WorkOrderBOMGridABS] #WorkOrderId", param).ToList();
Assert.IsNotNull(baseList);
}
}
I was using an old table to get the Unit Of Measure value that had an integer ID value. I switched it to use a new table with a VARCHAR ID value. Making this change to the stored proc and model code allowed the FromRawSql to work. Not sure why because while the integer ID value was getting an integer, either 0 or number other than 0, it was a valid value for the model. Any error message I received did not mention this UnitId field. It was a pain but I am glad it is resolved. At least until the next error I run into that much is guaranteed.
Using ASP.Net core 3.0. my Database query works - I can get the result set (records), but how to pass/get the output parameter? Also would like to know if there's a way to get the return value.
I tried using different ways to call the SQL query and the only one I was able to get working was FromSqlInterpolated, but open to different methods.
This code works for me, but I want to pass an additional parameter that can get populated as an output parameter (which is working when I test it by calling the stored proc from within SQL Server).
var result = _context.Users
.FromSqlInterpolated($"EXEC mystoredproc {user.Username} ").AsEnumerable().FirstOrDefault();
I tried creating a variable before the call
string out1 = null;
And then including that in the call but I can't figure out the syntax and I'm not sure if it's supported with this method.
var result = _context.Users
.FromSqlInterpolated($"EXEC mystoredproc {user.Username}, OUTPUT {out1}").AsEnumerable().FirstOrDefault();
Console.WriteLine(out1);
Hoping someone can point me in the right direction - would like to know both how to use the output parameter and how to get the return value, not just the record set. Thank you.
The answer accepted does not seem to work for me.
However I finally manage to have the OUTPUT parameter work by using the following code
var p0 = new SqlParameter("#userName", {user.Username});
var p1 = new SqlParameter("#out1", System.Data.SqlDbType.NVarChar, 20) { Direction = System.Data.ParameterDirection.Output };
string out1 = null;
var result = _context.Users
.FromSqlRaw($"EXEC mystoredproc #userName, #out1 OUTPUT ", p0, p1).AsEnumerable().FirstOrDefault();
Console.WriteLine(p1.Value); // Contains the new value of the p1 parameter
Just a litte warning, the p1 value property will be changed only when the request will be executed (by an AsEnumerable, Load() or anything that forces the Sql execution)
I am developing a mater-detail page where I can insert a new row into a details table (AstAssetReturnsVO) and set its referential key to the ID of the master table (AstAssetsVO). The code is run as part of a method call activity right before I get to the JSFF call.
For some reason I get the NullPointerException when it gets to the tagged line below and I have no idea why getCurrentRow returns a null pointer. I checked the documentation here and it is supposed to return the current row of the iterator corresponding to the current row of the data control.
Please let me know what I am possibly doing wrong.
Best Regards,
public void assetReturnInitialization(){
getAstAssetReturnsVO().clearCache();
getAstAssetReturnsVO().executeEmptyRowSet();
Row row = getAstAssetReturnsVO().createRow();
row.setAttribute("Stat", 99);
row.setAttribute("AsrtDate", "1396/12/31");
getAstAssetsVO().executeQuery();
Row assetRow = getAstAssetsVO().getCurrentRow(); <<<<<<< ERROR OCCURS HERE
row.setAttribute("AsetId", assetRow.getAttribute("Id"));
getAstAssetsVO().getCurrentRow().setAttribute("Status", "Returned".toUpperCase());
getAstAssetReturnsVO().insertRow(row);
getAstAssetReturnsVO().setCurrentRow(row);
return ;
}
getAstAssetsVO().executeQuery();
Row assetRow = getAstAssetsVO().getCurrentRow(); <<<<<<< ERROR OCCURS HERE
This answer is specific to above two lines of code. I did not review your use case and rest of the code.
After vo.executeQuery() API, row iterator would point to one above the first row. So, you have two options. Either use vo.hasNext() to check if there is next row and loop through the records or if you just need first row, then use vo.first() to get it. Below is the sample code for later case.
getAstAssetsVO().executeQuery();
Row assetRow = getAstAssetsVO().first();
if (assetRow != null) {
//your logic
}
I use delphi XE5, I have a database with 7 tables, and my problem: I click on a button which runs this code:
dbgridappr2.Enabled:=false;
adoquery4.Parameters.Clear;
datasource6.DataSet:=adoquery4;
ADOQuery4:=TADOQuery.Create(Application);
adoquery4.Active:=False;
adoquery4.Connection:=ADOConnection1;
adoquery4.SQL.Clear;
adoquery4.SQL.Add('select SPEC.ISp AS ''Spécialité'',COUNT(APPR.NValAp) AS ''Nombre dApprentis de même Spécialité'' ');
adoquery4.SQL.Add('FROM APPR,SPEC ');
adoquery4.SQL.Add('where SPEC.CSp=APPR.CSp ');
adoquery4.SQL.Add('GROUP BY SPEC.ISp ');
adoquery4.SQL.Add('ORDER BY COUNT(APPR.NValAp) desc ');
ADOQuery4.Prepared := True;
ADOQuery4.ExecSQL;
//adoquery4.Open;
adoquery4.Active:=true;
dbgridappr2.Visible:=true;
dbgridappr2.DataSource:=datasource6;
dbgridappr2.Enabled:=true;
I have the result in a DbGrid but the message error show incorrect parameter ??
I changed the button code but I always get the same error message. I have 10 buttons that all run similar code with different AdoQuery and I have the result but I have always the same message error
The code you've posted is an absolute mess. Here's why:
You clear the adoquery4.Parameters here, and assign adoquery4 to datasource6.DataSet:
dbgridappr2.Enabled:=false;
adoquery4.Parameters.Clear;
datasource6.DataSet:=adoquery4;
You then immediately throw away the existing adoquery4 (leaking memory in the process), and replace it with a new instance of TADOQuery:
ADOQuery4:=TADOQuery.Create(Application);
You then close the newly created ADOQuery4 (which could not possibly be Active at this point), assign a connection (which would be fine), and clear the SQL (which could not possibly have any content here):
adoquery4.Active:=False;
adoquery4.Connection:=ADOConnection1;
adoquery4.SQL.Clear;
So far, about 90% of what you've done is meaningless.
Then you make the mistake of calling ADOQuery4.ExecSQL;, which is used to execute queries that return no rowset, like INSERT, DELETE, and so forth. You need to use ADOQuery4.Open or ADOQuery4.Active := True instead for a SELECT. This is the actual cause of the error you're getting; you're calling ExecSQL with an SQL statement that returns a rowset, and that's invalid.
Let's try again, and throw in a slight improvement in the SQL in the process. Ignore everything you've posted here, and start over:
ADOQuery4.DisableControls;
try
// If the query is
if ADOQuery4.Active then
ADOQuery4.Close;
ADOQuery4.Parameters.Clear;
ADOQuery4.SQL.Clear;
AdoQuery4.SQL.Add('select SPEC.ISp AS ''Spécialité'',');
AdoQuery4.SQL.Add('COUNT(APPR.NValAp) AS ''Nombre dApprentis de même Spécialité''');
AdoQuery4.SQL.Add('FROM APPR INNER JOIN SPEC');
AdoQuery4.SQL.Add('ON SPEC.CSp = APPR.CSp');
AdoQuery4.SQL.Add('GROUP BY SPEC.ISp ');
AdoQuery4.SQL.Add('ORDER BY COUNT(APPR.NValAp) desc');
ADOQuery4.Open;
finally
ADOQuery4.EnableControls;
end;
(I don't know what all of the juggling of the dbgridappr2.DataSource is about, but unless you're changing the datasource from a different query none of that is necessary. The calls to DisableControls and EnableControls stops any UI components from being updated while the new query is executed.)
I'm having a lot of trouble inserting text stored in a var into a table. Check out my code:
function updateTable(){
var text = "finally";
db.transaction(
function(transaction) {
transaction.executeSql('INSERT INTO Comentario (ComentarioCirc1, ComentarioCirc2) VALUES (text, "2")');
}
);
}
I've tried a lot of solutions but nothing worked. It should be so simple to do, what am I doing wrong? No data is inserted in the table and no error messages are shown also,
to fix your query you need to add value of text variable, like this:
transaction.executeSql('INSERT INTO Comentario (ComentarioCirc1, ComentarioCirc2) VALUES ("' + text + '", "2")');
but what you really should do is use parameterized SQL, like this:
transaction.executeSql('INSERT INTO Comentario (ComentarioCirc1, ComentarioCirc2) VALUES (?, "2")', [text]);
and if you want to know whether query succeeded or not you should pass success and error calbacks as third and fourth argument of executeSql.
I'd also suggest befriending webdatabase specification as it will answer a lot of other questions you will likely have ;)