I’m using SQL Server 2008 R2 and C# ASP.NET 4
I have this simplified table named myTable including the columns:
Col1, Col2, Col3, Col4
CREATE TABLE [dbo].[myTable](
[Col1] [int] NULL,
[Col2] [int] NULL,
[Col3] [nvarchar](50) NULL,
[Col4] [int] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[myTable] ([Col1], [Col2], [Col3], [Col4]) VALUES (0, 0, N'@', 0)
INSERT [dbo].[myTable] ([Col1], [Col2], [Col3], [Col4]) VALUES (1, 2, N'c', 4)
INSERT [dbo].[myTable] ([Col1], [Col2], [Col3], [Col4]) VALUES (11, 22, N'cc', 44)
(The original table is much wider)
How to SELECT two (or 20 or 200) column into C# variables or array/list of variables, or anything else which will be effective as or better than sometihng like that:
object obj = new object();
string sql = "SELECT Col2, Col3 FROM myTable WHERE Col1=0";
using (SqlConnection conn = new SqlConnection(mySqlCalss.DatabaseConnectionString() ))
{
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Connection.Open();
obj = cmd.ExecuteNonQuery();
}
in a way I could use something like:
int myVar1 = (int)ojb[0];
string myVar2 = (string)obj[1];
then:
lblMyASPlable1.Text = myVar1.ToString();
lblMyASPlable2.Text = myVar2;
?
You need
SQLDataAdapterAnd