Unknown table name in VB.net using microsoft Access? - vb.net

Sorry if my subject isn't clear enough because I don't know how else to put. So here's the thing, I need to debug and test a VB.NET windows application for hotel management system. I'm quite new to VB.NET, so there is a few lines of database query that I didn't get. There is a few lines such as :
Com.CommandText = "Select * from QRoom Order by RoomNo"
or
Com.CommandText = "Select Floor from QRoom where RoomNo=" & cbo.Text & ""
as you can see the table name there is QRoom but when I check within the Access database, there is no table name QRoom. But if I change the table name to the one that us in the database(which is my case, it is TblRoom), then there will be errors. So I didn't get why is that. Any help is appreciated.
p/s : the guy who wrote this code is unreachable st the moment so I cannot directly ask him. :(

Related

Volusion's generic SQL folder, functionality

I found this response very helpful
How to write join query in Volusion API
What I'm looking for is a way to add my own .SQL and .XSD files to the /vspfiles/schema/Generic folder and be able to pass parameters to it. Does anyone know if that's possible.
A very basic example of the SQL would be something like this...
select * from Orders where order_id = "-ORDERID-"
...and I'd be able to pass in the "-ORDERID-" as a variable.
Or even better the SQL file would just be this "-SQL-" and I could pass in the entire SQL string myself. Thanks!
Thanks user357034 for getting me here (I'd "up" your answer but I'm new and don't have any reputation). I wanted to post the code I used in case others run into this. And also get any feedback if you see anything that looks goofy here.
First, I created an ASP file like so
Dim orderid
Dim status
orderid = Request.QueryString("orderid")
status = Request.QueryString("status")
sql = " update Orders " & _
" set OrderStatus = '" + status + "' " & _
" where Orderid in (" + orderid + ") " ;
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("./MY_FILE.sql"),2,true)
f.WriteLine(sql)
f.Close
set f=Nothing
set fs=Nothing
I FTPed that up to the "generic" folder on Volusion.
Next, in PHP, I call this file, similar to this...
$asp = file("http://MY_SITE/v/vspfiles/schema/generic/MY_FILE.asp?
orderid=11,12&status=Processing");
foreach ( $asp as $line )
{
echo ($line);
}
NOTE: I already FTPed an XSD file to the same folder with the same name, like MY_FILE.xsd.
And finally, I make a web service call to my service, like this...
$url = "http://MY_SITE/net/WebService.aspx?
Login=XXXX&EncryptedPassword=YYYYY&API_Name=Generic\MY_FILE"
Works great. I go into the Volusion admin site, look at the Orders 11 and 12, and they were updated. I'm using this method for several areas in Volusion where their API is lacking. Thanks!
While technically one could pass in text comprised of a complete SQL query, however I would strongly caution against such practice as it would open up your site to malicious activity and/or possible security issues. I would limit the scope to a specific query and only allow one or more parameters to be used.
To accomplish this you have to create an custom ASP page in Volusion that would gather the parameters from the user, in your case "order id" and then insert them into the set SQL query, write that SQL query as a text file to the server in the correct location as shown in https://stackoverflow.com/a/29134928/357034 and then execute the query. All this is done in the custom ASP page.
UPDATE: If you just want a simple order id query with all fields returned you don't even have to use the the SQL method as Volusion already has a built in method to return this data. You just have to use a custom ASP page to insert the order id parameter and then execute the URL with the parameter attached. In your ASP page you would insert the order id in place of the xxxxx
http://www.yoursiteurl.com/net/WebService.aspx?Login=name#yoursiteurl.com&EncryptedPassword=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxC&EDI_Name=Generic\Orders&SELECT_Columns=*&WHERE_Column=o.OrderID&WHERE_Value=xxxxx

WP8 SQlite Select Query

I have following code.
string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Questions.sqlite");
SQLiteConnection dbConn = new SQLiteConnection(DB_PATH);
dbConn.CreateTable<QuestionModel>();
// Some code which insert the records in database from webservices.
List<QuestionModel> questionsList = dbConn.Table<QuestionModel>().ToList();
System.Diagnostics.Debug.WriteLine("List Count " + dbConn.Table<QuestionModel>().ToList().Count);
The List Count gives me 0 always. But When I use WP POWER TOOLS and get the Questions.sqlite file from emulator. It gives me records in SQLite table.
I also check the query in http://sqlitestudio.pl/ on the same Questions.sqlite but that gives me records as it should.
I tried other way to get the records as following code but none them were working.
String query = "Select * from QuestionModel;";
questionsList = dbConn.Query<QuestionModel>(query);
System.Diagnostics.Debug.WriteLine("List Count " + questionsList.Count);
With your analysis seems like only the row List<QuestionModel> questionsList = dbConn.Table<QuestionModel>().ToList(); is not working.
I helped someone in SQLiteDB on WP8 a couple of days ago, here is his question : SQLite WP8 StackOverflow
If you compare his code with your code, you are missing the Model bindind :
db.GetTableInfo("QuestionModel");
And
db.Table<QuestionModel>().ToList<QuestionModel>();
Not important but use your list variable to get count in debug write to not retrieve twice the list questionsList.Count
Hope it helps.

MS SQL Server 2012 returning blank text?

I execute this inside MS SQL Server Management Studio:
SELECT TOP 2 * FROM searchdb.dbo.tblnames;
I get back two posts with full information.
When I execute the same on a webpage I however get all information except for text, which is blank.
The type of the text columns in the database are:
ntext
The connection string I'm using:
Driver={SQL Server};Server=localhost;Database=searchdb;Uid=myuser;Pwd=mypass;
I've also tried with:
Driver={SQL Server Native Client 11.0};Server=localhost;Database=searchdb;Uid=myuser;Pwd=mypass;
Getting the same result. I don't know the difference between "SQL Server" and "SQL Server Native Client 11.0", just that "SQL Server" has a newer date in the list of ODBC Data Sources.
What's going on? Why is it returning blank text? How do I fix this?
Edit: Here is the code I'm using on the ASP web pages:
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Driver={SQL Server};Server=localhost;Database=searchdb;Uid=myuser;Pwd=mypass;"
Set RecSet = Conn.Execute("SELECT TOP 2 * FROM tblnames;")
Response.Write "ID: "& RecSet("ID") &"<br>"
Response.Write "Name: "& RecSet("name") &"<br>"
Response.Write "Mark: "& RecSet("mark") &"<br>"
RecSet.MoveNext
Response.Write "ID: "& RecSet("ID") &"<br>"
Response.Write "Name: "& RecSet("name") &"<br>"
Response.Write "Mark: "& RecSet("mark") &"<br>"
Set RecSet = Nothing
Both the ID and Mark columns have "int" data type and show up fine, while the "name" column is blank.
Edit 2:
Users with less than 10 reputation can't answer their own question
for 8 hours after asking. You can answer 3/15/2014 4:16:50 AM. Until
then please use comments, or edit your question instead.
It's dumb that you have to make an account on stackoverflow (didn't have to before), and that you can't answer your own questions on a new account. And I hope some mod doesn't edit this post. If things are wrong with your system it's important that people can point it out.
Anyways, here is the answer:
Self-answered:
I changed my connection string to:
Provider=SQL Server Native Client 11.0;Server=localhost;Database=searchdb;Uid=myuser;Pwd=mypass;
Now everything works fine.
I have no idea why it didn't work correctly when I used that one as "Driver" but whatever. Note that just "Provider=SQL Server" didn't work at all, while "Driver={SQL Server}" worked exactly the same as "Driver={SQL Server Native Client 11.0}" (that is, with blank text).
No idea how Provider is different than Driver. "Provider" isn't even mentioned anywhere in Control Panel > Administrative Tools > ODBC Data Sources.
After some testing it seems like both Driver and Provider is just as fast as each other too, so there's no benefit from using Driver, it is just broken.
It looks like changing your query to use a column list, rather than the asterisk, could take care of the issue. Also, I read that your ntext field should be the last column in your list. Seems strange, but it's worth a shot.
Resources:
http://databases.aspfaq.com/database/how-do-i-deal-with-memo-text-hyperlink-and-currency-columns.html
SQL Server text column affects results returned to classic ASP
EDIT:
You also might try converting the ntext to an nvarchar in your sql statement.
SELECT TOP 2 ID, Mark, CONVERT(NVARCHAR(MAX), Name) [Name] FROM tblNames

SQL Server datetime culture (localization) headache

SQL Server 2005. Visual Studio 2010. ASP.NET 2.0 Web Application
This is a web application that supports multiple languages, one of them is Korean. I have “langid” in the query string to differentiate different languages, if langid=3 it is Korean.
In my code behind’ C# code, I read a table using this query:
"select * from Reservations where rsv_id = 1234"
There is a column named "rsv_date" in the table which is reservation date, of type datetime. In the db table its value is "11/22/2012 4:14:37 PM". I checked this in SQL server management studio. But when I read it out, I got "2012-11-22 오후 4:14:37"! Where does that Korean “오후” come from??? Is it because of some culture setting anywhere? But I don’t see where, either in my code or in SQL Server. This caused problem for me, because when I modify this record, it will try to write "2012-11-22 오후 4:14:37" to the db, which of course SQL server reports error.
My original code:
Hashtable reservation = new Hashtable();
SqlCommand sqlCommand = null;
SqlDataReader dataReader;
string queryCommand = "select * from Reservations where rsv_id = #RsvID";
sqlCommand = new SqlCommand(queryCommand, getConnection());
sqlCommand.Connection.Open();
sqlCommand.Parameters.AddWithValue("#RsvID", rsvID);
dataReader = sqlCommand.ExecuteReader();
while (dataReader.Read())
{
reservation["rsvID"] = dataReader["rsv_id"];
reservation["rsvCode"] = dataReader["rsv_code"];
reservation["rsvType"] = dataReader["rsv_type"];
reservation["rsvDate"] = dataReader["rsv_date"]; // where does Korean come from?
...
}
It's a common misunderstanding that you can "check" the format of datetime fields in the database.
The format you see on screen will always depend on the client, even if the client is "SQL server management studio".
In the database, the datetime is stored in a binary format that very few need to know.
So, the Korean characters are from the client, in this case your own program.
And Yes, they will depend on some culture setting somewhere.
Your example doesn't show what happens to reservation["rsvDate"] , where is the value displayed with the Korean characters ?
How are you trying to write the value with Korean characters to the database ?
To avoid Korean characters you could use .ToString(CultureInfo.InvariantCulture) where you use the Date value.

Create a Crystal Report with dynamic tables at runtime

Hello I'm planning an application that is basically a reporting front-end for a database (proprietary Pervasive SQL) using an ODBC dsn-less connection string.
I am able to create the dataset in Visual Studio and link up the report(s) to the app. However in real world usage, the location of the database will be different per user. That is not the main problem. I overcame that with the connection string that allows you to set the location of the database path.
Here's the kicker...
The name of the tables that I want to read from are prefixed with a unique filename (actually the same name I mentioned above). I need crystal to re-map the table names at runtime. Just the table name prefixes really. The fields and names of the fields will not change.
Any ideas on where I should look for writing this block? I am using VS2010 & C# if that helps. I think thee should be some sort of class files that come with Crystal that can do some runtime reflection to get/set the table names?
Any thoughts would be welcome and appreciated.
Rob
Edit: I found some documents link that has API docs and other support. I will be studying them. They are all .chm files (Windows help files) so there is no "online" docs to search for.
Add a Crystal reportViewer change the name to objReport
add a public function ShowReport()
public void ShowReport(ReportDocument objReport)
{
Cursor.Current = Cursors.WaitCursor;
objReport.SetDatabaseLogon("", "dbpassword");
cRep.ReportSource = objReport;
this.Show();
Cursor.Current = Cursors.Default;
}
And Call it from anywhere in your application
ds = GetDataInDataSet();//fILL DataSet with your data
rptPSummary objRpt = new rptPSummary();
objRpt.SummaryInfo.ReportComments = "Have a nice day";
objRpt.SummaryInfo.ReportTitle = "Purchase Summary Report from " + sDate.ToString("dd/MM/yyyy") + " to " + eDate.ToString("dd/MM/yyyy");
objRpt.SetDataSource(ds);
frmReportView frmRpt = new frmReportView();
frmRpt.Text = objRpt.SummaryInfo.ReportTitle;
frmRpt.MdiParent = this;
frmRpt.ShowReport(objRpt);