日付は(23.02.2015) のように見える文字列をプロブラムに挿入して、データグリッドビューからローカルデータベースの日付カラムに挿入することです。データベースの日付欄に日付のように見える文字列を挿入
私は私の文字列 "23.02.2015"を23/02/2015に転送し、それを日付変数に変換する必要があることを知っています。私はそれをデータベースの日付列に挿入します。しかし、 :短い中
private void button3_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string constring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\john\Documents\Visual Studio 2015\Projects\Project\Project\DB.mdf;Integrated Security=True";
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO ResultsTable VALUES(@Date, @TagNumber)", con))
{
cmd.Parameters.AddWithValue("@Date", row.Cells["Exposure Date"].Value);
cmd.Parameters.AddWithValue("@TagNumber", row.Cells["Device #"].Value);
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("Records inserted.");
}
- 私のコードでは、私のデータベースの日付欄にそれを挿入することが23/05/2014のような日付型に「2014年5月23日」のような文字列を変換するproblamを持つイム。
'Convert.ToDateTime(Regex.Replace(input、"。 "、"/"))'のような文字列を挿入する前に文字列を自動的にdatetimeに変換しますか? –
はい!私のコードでは、この行をどこに挿入するのですか? – shlezz