| | |
Get the column values from the SQLite database
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hello guys, can someone tell me how can I get the values from the columns ?
My sql table is:
Table name: settbl
Table columns: id, first (int), second (int)
...and now, I want to get the values from "first" and "second", but I got the error message "Object reference no set to an instance of an object".
This is my code:
Thanks...
My sql table is:
Table name: settbl
Table columns: id, first (int), second (int)
...and now, I want to get the values from "first" and "second", but I got the error message "Object reference no set to an instance of an object".
This is my code:
C# Syntax (Toggle Plain Text)
sqlIteCon = new SQLiteConnection("Data Source=set.db;Version=3;New=False;Compress=True;"); sqlIteCon.Open(); string SelectQuery = "SELECT * FROM settbl"; SQLiteCommand sqlCommand = new SQLiteCommand(SelectQuery, sqlIteCon); SQLiteDataReader sqlRead = sqlCommand.ExecuteReader(); int a = sqlRead.GetInt32(sqlRead.GetOrdinal("first")); int b = sqlRead.GetInt32(sqlRead.GetOrdinal("second"));
Thanks...
0
#2 Oct 31st, 2009
Why not load it in to a
DataTable ? C# Syntax (Toggle Plain Text)
private void button9999_Click(object sender, EventArgs e) { const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select * From Invoice Where InvNumber = @InvNumber"; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add(new SqlParameter("@InvNumber", 1100)); using (SqlDataReader dr = cmd.ExecuteReader()) { using (DataTable dt = new DataTable()) { dt.Load(dr); for (int i1 = 0; i1 < dt.Rows.Count; i1++) { DataRow row = dt.Rows[i1]; string custName = Convert.ToString(row["CustName"]); string email = Convert.ToString(row["Email"]); } } } } conn.Close(); } }
0
#3 Nov 1st, 2009
Sknake, thanks for your help/example, but I solved mu problem with the SQLiteDataReader Class
C# Syntax (Toggle Plain Text)
public void ReadMyData(string myConnString) { string mySelectQuery = "SELECT DeptNo, DName FROM Dept"; SQLiteConnection sqConnection = new SQLiteConnection(myConnString); SQLiteCommand sqCommand = new SQLiteCommand(mySelectQuery,sqConnection); sqConnection.Open(); try { SQLiteDataReader sqReader = sqCommand.ExecuteReader(); while (sqReader.Read()) { Console.WriteLine(sqReader.GetInt32(0) + ", " + sqReader.GetString(sqReader.GetOrdinal("DName"))); } sqReader.Close(); } finally { sqConnection.Close(); } }
![]() |
Other Threads in the C# Forum
- Previous Thread: Voice Streaming
- Next Thread: WPF WebBrowser Control
Views: 403 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap button buttons c# check checkbox class client code color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing enum event excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path picturebox pixelinversion post programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






