I tried to change the string name of the movie (movie name) to int32 (movie id #) in my movie Print ID number Is there something wrong with me? This is due to the error mentioned:
Unable to type 'System.Data.SqlClient.SqlConnection' type of type 'System.IConvertible'
My code:
string file name, connectionInfo; SqlConnection DB; This.listBox1.Items.Clear (); Filename = "netflix.mdf"; ConnectionInfo = String.Format (@ "Data Source = (LocalBible) \ v11.0; Attached FillName = | DataDirectory | \ {0}; Integrated Security = True;", File Name); Db = new SqlConnection (connectionInfo); Db.Open (); SqlCommand CMD = new SQL Commands (); CMD Connection = DB; String moviename = textbox1.Text; Cmd.CommandText = string.Format (@ "Select movie from movies where movie name = '{0}';", moviename); SqlDataAdapter Adapter = New SqlDataAdapter (CMD); Dataset ds = new dataset (); Adapter.fill (ds); Db.Close (); Int id = System.Convert.ToInt32 (cmd); This.listBox1.Items.Add (ID);
To execute the query view, your CMD object is not the result of a query in the method This will return a SqlDataReader object which is used for the query results iterations.
This is an example of MSDN:
using (SqlConnection connection = New SqlConnection (connectionString)) {connection.Open (); SqlCommand command = new SqlCommand (queryString, Connection); SqlDataReader Reader = command.ExecuteReader (); While (reader.Read ()) {Console.WriteLine (String.Format ("{0}", Reader [0])); }}
In this example, queryString
will be your query select movies from movies where ...
and connections
Your DB object will be
Object Reader
can be added as an array (Property Indexer), Reader [0]
The value is included after the first reading, after the first column in the form of an object, select value in multiple reads before the resulting rows, the value of the column repeated
In addition to this, you can not put any string on an int, you need or tryParse method to change a string to an int
change the first column To whom you know it is a string for an int, it will be int.Parse (string) reader [0])
No comments:
Post a Comment