Datepicker值如何保存在databaseC#中? [英] how Datepicker value save in databaseC#?

查看:48
本文介绍了Datepicker值如何保存在databaseC#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void listView2_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView2.SelectedItems.Count == 0)
{
listView2.SelectedItems[0].ForeColor = System.Drawing.Color.Blue;
}
 

if (listView2.SelectedIndices.Count <= 0)
{
return;
 
}
 
int intselectedindex = listView2.SelectedIndices[0];
 
if (intselectedindex >= 0)
{
 
var text1 = listView2.Items[intselectedindex].Text;

 

SqlConnection myConnection1 = new SqlConnection("Server=(local);Database=General;Trusted_Connection=True;");
myConnection1.Open();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand myCommand1 = new SqlCommand();
myCommand1.CommandText = "SELECT CompanyName FROM dbo.View_2 WHERE YearLabel= " + text1;
 

 

myCommand1.CommandType = CommandType.Text;
 
myCommand1.Connection = myConnection1;

 

 
try
{
SqlDataReader reader = myCommand1.ExecuteReader();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(myCommand1);
DataTable dt = new DataTable();
ds.Tables.Add(dt);
 

while (reader.Read())
{
listView1.Items.Add(reader["CompanyName"].ToString());
 
}
 

if (reader.HasRows)
{
 
dt.Load(reader);
sda.Fill(dt);
listView1.View = View.Tile;
listView1.HeaderStyle = ColumnHeaderStyle.None;
listView1.Columns.Add("Company Name", 250);
listView1.GridLines = true;

myConnection1.Close();
}

}
 
catch (System.Data.SqlClient.SqlException sqlException)
{
System.Windows.Forms.MessageBox.Show(sqlException.Message);
myConnection1.Close();
myConnection1.Dispose();
}
}
}
}

推荐答案

请尝试以下链接..



1)在表格之间传递数据



2)在.NET中的表单之间传递值
Try this below links..

1 ) Passing Data Between Forms

2 ) Passing Values Between Forms in .NET


这篇关于Datepicker值如何保存在databaseC#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆