TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Goran Bibic
475
2.9k
201k
Select conection string from label value c#
Sep 5 2018 4:36 AM
I have two conections added in app
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name=
"test_2017_2018.Properties.Settings.TEST_2017"
connectionString=
"Data Source=.\SQLEXPRESS;Initial Catalog=2017;Integrated Security=True"
providerName=
"System.Data.SqlClient"
/>
<add name=
"test_2017_2018.Properties.Settings.TEST_2018"
connectionString=
"Data Source=.\SQLEXPRESS;Initial Catalog=2018;Integrated Security=True"
providerName=
"System.Data.SqlClient"
/>
</connectionStrings>
<startup>
<supportedRuntime version=
"v4.0"
sku=
".NETFramework,Version=v4.6.1"
/>
</startup>
</configuration>
Define conections in c# app winform
string
cs2017 = Properties.Settings.Default.TEST_2017;
string
cs2018 = Properties.Settings.Default.TEST_2018;
When login choose in combobox value (2017 or 2018)
Use that
InitializeComponent();
godinalabel.Text = getGodina();
That is ok...now i need
public
void
PullData()
{
if
(godinalabel.Text ==
"2017"
)
{
SqlConnection connString =
new
SqlConnection(cs2017);
}
else
if
(godinalabel.Text ==
"2018"
)
{
SqlConnection connString =
new
SqlConnection(cs2018);
}
}
To fill datagrid
private
void
Izvjestajoprodanimartiklima()
{
using
(SqlConnection openCon =
new
SqlConnection(PullData))
{
String saveStaff =
"SELECT * from partners "
;
Console.WriteLine(saveStaff);
openCon.Open();
using
(SqlDataAdapter querySaveStaff =
new
SqlDataAdapter(saveStaff, cs))
{
DataTable dt =
new
DataTable();
DataColumn column =
new
DataColumn();
column.DataType = System.Type.GetType(
"System.Int32"
);
column.ColumnName =
"Redni broj"
;
column.AutoIncrement =
true
;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
dt.Columns.Add(column);
int
index = -1;
foreach
(DataRow row
in
dt.Rows)
{
row.SetField(column, ++index);
}
querySaveStaff.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Update();
dataGridView1.Refresh();
}
}
}
Error is this line Pulldata when fill datagrid
using
(SqlConnection openCon =
new
SqlConnection(PullData))
Some help_
Reply
Answers (
5
)
How can we test the stored procedure from the database by us
Select query when date range given by TextBoxes...