当前位置: 首页>>代码示例>>C#>>正文


C# SqlConnection.ToString方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlConnection.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnection.ToString方法的具体用法?C# SqlConnection.ToString怎么用?C# SqlConnection.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlConnection的用法示例。


在下文中一共展示了SqlConnection.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: insertdatetime

 void insertdatetime(string type)
 {
     using (SqlConnection con = new SqlConnection())
     {
         con.ConnectionString = CommonHelperclasses.readconnectionstring.getconstringfromconfig();
         SqlCommand cmd = new SqlCommand(con.ToString());
         cmd.CommandText = "update lastruntime set lastrundatetime =getdate() jobtype [email protected]";
         cmd.CommandType = CommandType.Text;
         cmd.Parameters.AddWithValue("@type", type);
         con.Open();
         cmd.ExecuteNonQuery();
         con.Close();
     }
 }
开发者ID:sateeshcodes,项目名称:jobsandservices,代码行数:14,代码来源:updatetimestamp.cs

示例2: ButtonAddDvd_Click

        protected void ButtonAddDvd_Click(object sender, EventArgs e)
        {
            string res = ""; //hidden sql connection result variable
            SqlConnection conn;
            SqlCommand comm, commdet;
            string connectionString = ConfigurationManager.ConnectionStrings["DVDconnstring"].ConnectionString;
            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("INSERT INTO DVDtable (DVDtitle, DVDartist, DVDrating, DVDprice) "
                + " VALUES (@DVDtitle, @DVDartist, @DVDrating, @DVDprice); SELECT SCOPE_IDENTITY();", conn);
            commdet = new SqlCommand("INSERT INTO Details(DVDID, Description, PicURL) "
                + "VALUES ( @DVDID, @Description, @PicURL)", conn);
            try //declare parameters and enter data
            {
                comm.Parameters.Add("@DVDtitle", System.Data.SqlDbType.NVarChar);
                comm.Parameters["@DVDtitle"].Value = textboxDVDTitle.Text; //  "meow"; //
                comm.Parameters.Add("@DVDartist", System.Data.SqlDbType.NVarChar);
                comm.Parameters["@DVDartist"].Value = textboxDVDArtist.Text; //"meow"; //
                comm.Parameters.Add("@DVDrating", System.Data.SqlDbType.Int);
                comm.Parameters["@DVDrating"].Value = Convert.ToInt32(textboxDVDRating.Text); // 1; //
                comm.Parameters.Add("@DVDprice", System.Data.SqlDbType.Money);
                comm.Parameters["@DVDprice"].Value  = Convert.ToDouble(textboxDVDPrice.Text); // 1; //

            }
            catch //catch errors in comm declarations such as text entered into numeric fields
            {
                dbErrorLabel.Text = "Something was entered wrong.";
                res += comm.ToString() + "\n"
                    + comm.Parameters.ToString() + "\n";
            }

            try //connect to SQL
            {
                dbErrorLabel.Text = "Connecting...";
                conn.Open();

                if (textboxDVDDescription.Text != "" && textboxDVDDescription.Text != null)
                {
                    commdet.Parameters.Add("@DVDID", System.Data.SqlDbType.Int);
                    commdet.Parameters.Add("@Description", System.Data.SqlDbType.NVarChar, 500);
                    commdet.Parameters.Add("@PicURL", System.Data.SqlDbType.NVarChar, 100);

                    commdet.Parameters["@DVDID"].Value = comm.ExecuteScalar();
                    dbErrorLabel.Text = " DVD named " + comm.Parameters["@DVDtitle"].Value + " was added! ";
                    commdet.Parameters["@Description"].Value = textboxDVDDescription.Text;
                    commdet.Parameters["@PicURL"].Value = textboxDVDPicURL.Text;
                    dbErrorLabel.Text += " " + commdet.ExecuteNonQuery() + " detail added.";
                }else
                {
                    comm.ExecuteScalar();
                    dbErrorLabel.Text = " DVD named " + comm.Parameters["@DVDtitle"].Value + " was added! ";
                }

                InterfaceClearFields();
            }
            catch (SqlException se) //catches sql failures and rejections
            {
                dbErrorLabel.Text += "There was an error adding this DVD entry to the system. "+ se.ToString();
                res += se.ToString() + "\n" + e.ToString() + "\n";
            }
            finally
            {
                res += "results of execution. \n"
                    + comm.Parameters[0].Value + "\n"
                    + conn.ToString() + " " + conn.State + "\n closing connection... ";
                conn.Close();
                res += conn.State +"\n";
            }
        }
开发者ID:jeffersoneagley,项目名称:PROG117,代码行数:68,代码来源:AddDVD.aspx.cs


注:本文中的System.Data.SqlClient.SqlConnection.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。